Mr-Vicky-01 commited on
Commit
f6b082a
1 Parent(s): aa8ebd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -1,5 +1,6 @@
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
@@ -12,13 +13,21 @@ api_key = os.getenv("HUGGINGFACE_API_TOKEN")
12
 
13
  os.environ['HUGGINGFACEHUB_API_TOKEN'] = api_key
14
 
15
-
16
- def get_summary_from_url(url):
17
- loaders = UnstructuredURLLoader(urls=[url])
18
- data = loaders.load()
19
- question = data[0]
20
-
21
- template = """{question}"""
 
 
 
 
 
 
 
 
22
  prompt = PromptTemplate(template=template, input_variables=["question"])
23
 
24
  llm_chain = LLMChain(prompt=prompt,
@@ -35,7 +44,8 @@ def text_to_speech(text, language='en'):
35
  return "output.mp3"
36
 
37
  def summarize_and_convert_to_audio(url):
38
- summary = get_summary_from_url(url)
 
39
  audio_file = text_to_speech(summary)
40
  return audio_file
41
 
 
1
  import gradio as gr
2
+ # from langchain.document_loaders import UnstructuredURLLoader
3
+ from langchain_community.document_loaders import WebBaseLoader
4
  import os
5
  from langchain import PromptTemplate, HuggingFaceHub, LLMChain
6
  from gtts import gTTS
 
13
 
14
  os.environ['HUGGINGFACEHUB_API_TOKEN'] = api_key
15
 
16
+ def get_url_text(url_link):
17
+ try:
18
+ loader = WebBaseLoader(url_link)
19
+ loader.requests_per_second = 1
20
+ docs = loader.aload()
21
+ extracted_text = ""
22
+ for page in docs:
23
+ extracted_text += page.page_content
24
+ return extracted_text
25
+ except Exception as e:
26
+ print(f"Error fetching or processing URL: {e}")
27
+ return ""
28
+
29
+ def get_answer(text):
30
+ template = """{text}"""
31
  prompt = PromptTemplate(template=template, input_variables=["question"])
32
 
33
  llm_chain = LLMChain(prompt=prompt,
 
44
  return "output.mp3"
45
 
46
  def summarize_and_convert_to_audio(url):
47
+ text = get_url_text(url)
48
+ summary = get_answer(text)
49
  audio_file = text_to_speech(summary)
50
  return audio_file
51