Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +41 -0
- requirements.txt +9 -0
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain.document_loaders import UnstructuredURLLoader
|
3 |
+
import os
|
4 |
+
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
|
5 |
+
from gtts import gTTS
|
6 |
+
from IPython.display import Audio
|
7 |
+
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
load_dotenv() # to load all the env variables
|
10 |
+
|
11 |
+
os.environ['HUGGINGFACEHUB_API_TOKEN'] = os.getenv("HUGGINGFACE_API_TOKEN")
|
12 |
+
|
13 |
+
|
14 |
+
def get_summary_from_url(url):
|
15 |
+
loaders = UnstructuredURLLoader(urls=[url])
|
16 |
+
data = loaders.load()
|
17 |
+
question = data[0]
|
18 |
+
|
19 |
+
template = """{question}"""
|
20 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
21 |
+
|
22 |
+
llm_chain = LLMChain(prompt=prompt,
|
23 |
+
llm=HuggingFaceHub(repo_id="Mr-Vicky-01/conversational_sumarization",
|
24 |
+
model_kwargs={"max_length":100,
|
25 |
+
"max_new_tokens":100,
|
26 |
+
"do_sample": False}))
|
27 |
+
answer = llm_chain.run(question)
|
28 |
+
return answer
|
29 |
+
|
30 |
+
def text_to_speech(text, language='en'):
|
31 |
+
tts = gTTS(text=text, lang=language)
|
32 |
+
tts.save("output.mp3")
|
33 |
+
return "output.mp3"
|
34 |
+
|
35 |
+
def summarize_and_convert_to_audio(url):
|
36 |
+
summary = get_summary_from_url(url)
|
37 |
+
audio_file = text_to_speech(summary)
|
38 |
+
return audio_file
|
39 |
+
|
40 |
+
iface = gr.Interface(fn=summarize_and_convert_to_audio, inputs="text", outputs="audio", title="Text Summarization & Audio Generation", description="Enter the URL of the article to summarize and convert to audio.")
|
41 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
unstructured==0.9.2
|
2 |
+
langchain
|
3 |
+
huggingface_hub
|
4 |
+
transformers
|
5 |
+
sentence_transformers
|
6 |
+
gTTS
|
7 |
+
gradio
|
8 |
+
langchain-community
|
9 |
+
IPython
|