mirror of
https://github.com/tcsenpai/easy-web-summarizer.git
synced 2025-06-06 10:35:20 +00:00
Added yt_summarizer to webui
This commit is contained in:
parent
e9a7d7c785
commit
eb95fc41a5
@ -45,7 +45,7 @@ def setup_summarization_chain():
|
||||
input_variables=["text"],
|
||||
)
|
||||
|
||||
llm = ChatOllama(model="llama3", base_url="http://0.0.0.0:11434")
|
||||
llm = ChatOllama(model="llama3", base_url="http://127.0.0.1:11434")
|
||||
llm_chain = LLMChain(llm=llm, prompt=prompt_template)
|
||||
return llm_chain
|
||||
|
||||
|
36
webui.py
36
webui.py
@ -1,9 +1,9 @@
|
||||
import gradio as gr
|
||||
|
||||
from summarizer import load_document, setup_summarization_chain
|
||||
from yt_summarizer import summarize_video
|
||||
from translator import setup_translator_chain
|
||||
|
||||
|
||||
def summarize(url):
|
||||
docs = load_document(url)
|
||||
llm_chain = setup_summarization_chain()
|
||||
@ -11,27 +11,50 @@ def summarize(url):
|
||||
|
||||
return [result, gr.Button("🇹🇷 Translate ", visible=True)]
|
||||
|
||||
|
||||
def translate(text):
|
||||
llm_chain = setup_translator_chain()
|
||||
result = llm_chain.run(text)
|
||||
return result
|
||||
|
||||
def update_ui(content_type):
|
||||
if content_type == "Web":
|
||||
# Set visibility for Web URL input to True and Video URL input to False
|
||||
url_visibility = "" # Empty string signifies no change for a text box.
|
||||
video_url_visibility = "" # Set video URL field to empty since it should be hidden.
|
||||
btn_text = "Generate Summary" # Button text for generating summary from a web URL
|
||||
elif content_type == "Video":
|
||||
# Set visibility for Web URL input to False and Video URL input to True
|
||||
url_visibility = "" # Set web URL field to empty since it should be hidden.
|
||||
video_url_visibility = "" # Empty string signifies no change for a text box.
|
||||
btn_text = "Summarize Video" # Button text for summarizing video content
|
||||
else:
|
||||
# Hide both inputs (unlikely to need this else, but just in case)
|
||||
url_visibility = ""
|
||||
video_url_visibility = ""
|
||||
btn_text = "" # Clear the button text
|
||||
|
||||
return url_visibility, video_url_visibility, btn_text
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(
|
||||
"""# Cobanov Web Summarizer
|
||||
Easily summarize any web page with a single click."""
|
||||
"""# Cobanov Web and Video Summarizer
|
||||
Easily summarize any web page or YouTube video with a single click."""
|
||||
)
|
||||
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
content_type = gr.Radio(choices=["Web", "Video"], label="Select Content Type", value="Web")
|
||||
|
||||
url = gr.Text(label="URL", placeholder="Enter URL here")
|
||||
video_url = gr.Text(label="YouTube Video URL", placeholder="Enter YouTube video URL here", visible=False)
|
||||
|
||||
btn_generate = gr.Button("Generate")
|
||||
|
||||
summary = gr.Markdown(label="Summary")
|
||||
btn_translate = gr.Button(visible=False)
|
||||
|
||||
content_type.change(update_ui, inputs=[content_type], outputs=[url, video_url, btn_generate])
|
||||
|
||||
gr.Examples(
|
||||
[
|
||||
"https://cobanov.dev/haftalik-bulten/hafta-13",
|
||||
@ -48,8 +71,9 @@ with gr.Blocks() as demo:
|
||||
Repo: github.com/mertcobanov/easy-web-summarizer
|
||||
```"""
|
||||
)
|
||||
btn_generate.click(summarize, inputs=[url], outputs=[summary, btn_translate])
|
||||
btn_generate.click(lambda url, video_url: summarize(url) if url else summarize_video(video_url),
|
||||
inputs=[url, video_url],
|
||||
outputs=[summary, btn_translate])
|
||||
btn_translate.click(translate, inputs=[summary], outputs=[summary])
|
||||
|
||||
|
||||
demo.launch()
|
@ -35,7 +35,4 @@ def summarize_video(video_link):
|
||||
sum_chain = yt_summarization_chain()
|
||||
result = sum_chain.run(chunks)
|
||||
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
#summarize_video()
|
||||
return result[0]
|
Loading…
x
Reference in New Issue
Block a user