diff --git a/summarizer.py b/summarizer.py index 9dbcf44..0489919 100644 --- a/summarizer.py +++ b/summarizer.py @@ -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 diff --git a/webui.py b/webui.py index 60f8c52..1747a8b 100644 --- a/webui.py +++ b/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,26 +11,49 @@ 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( [ @@ -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() +demo.launch() \ No newline at end of file diff --git a/yt_summarizer.py b/yt_summarizer.py index 6b98640..428524b 100644 --- a/yt_summarizer.py +++ b/yt_summarizer.py @@ -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() \ No newline at end of file + return result[0] \ No newline at end of file