Skip to content

Commit

Permalink
TUTORIAL 42
Browse files Browse the repository at this point in the history
  • Loading branch information
ronidas39 committed Feb 18, 2024
1 parent 2fdc4be commit a88ea86
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
Binary file not shown.
Binary file added tutorial42/__pycache__/downloadvideo.cpython-311.pyc
Binary file not shown.
Binary file added tutorial42/__pycache__/genvideo.cpython-311.pyc
Binary file not shown.
17 changes: 17 additions & 0 deletions tutorial42/downloadvideo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests

API_KEY="cm9uaWRhczA0MTk4N0BnbWFpbC5jb20:vU6fHQuEgIZK6zzLY8QK2"

def download_video(id):
url = "https://api.d-id.com/talks/"+id

headers = {
"accept": "application/json",
"authorization": f"Basic {API_KEY}"
}

response = requests.get(url, headers=headers)
print(response.json())
url=response.json()["result_url"]

return url
33 changes: 33 additions & 0 deletions tutorial42/genvideo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import requests

API_KEY="cm9uaWRhczA0MTk4N0BnbWFpbC5jb20:vU6fHQuEgIZK6zzLY8QK2"

url = "https://api.d-id.com/talks"

def genvideo(img_url,summary,v_id):

payload = {
"source_url":img_url,
"script": {
"type": "text",
"input": summary,
"provider": {
"type": "microsoft",
"voice_id": v_id,
"voice_config":{
"style":"Default"
}
}
}
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": f"Basic {API_KEY}"
}

response = requests.post(url, json=payload, headers=headers)

id=response.json()["id"]
print(id)
return id
33 changes: 33 additions & 0 deletions tutorial42/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain_community.tools import DuckDuckGoSearchResults
from langchain.docstore.document import Document
from langchain.chains.summarize import load_summarize_chain
from langchain.prompts import PromptTemplate
from genvideo import genvideo
from downloadvideo import download_video
import time
llm=ChatOpenAI(model="gpt-4",temperature=0.0)
ts="""
you are a news anchor for a global news channel,with this context genereate a concise summary of ther following
{text}
"""
pt=PromptTemplate(template=ts,input_variables=["text"])
st.set_page_config(page_title="24/7 NEWS CHANNEL POWERED BY AI DRIVEN NEWS ANCHOR")
st.header="what you want to hear and watch"
qsn=st.text_area("enter your query")
search=DuckDuckGoSearchResults(backend="news")
if st.button("Submit",type="primary"):
if qsn is not None:
result=search.run(qsn)
data=result.replace("[snippet: ","")
data=data[:-1]
docs=[Document(page_content=t) for t in data]
chain=load_summarize_chain(llm,chain_type="stuff",prompt=pt)
summary=chain.run(docs)
id=genvideo("https://clips-presenters.d-id.com/lana/uXbrIxQFjr/kzlKYBZ2wc/image.png",summary,"en-US-JaneNeural")
time.sleep(100)
url=download_video(id)
st.video(url)


Binary file added tutorial42/tutorial42.pptx
Binary file not shown.

0 comments on commit a88ea86

Please sign in to comment.