Spaces:
Sleeping
Sleeping
Initial commit with full functionality extend app req tools
Browse files- Gradio_UI.py +99 -0
- requirements.txt +2 -1
Gradio_UI.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gradio_UI.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from smolagents import CodeAgent
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
class GradioUI:
|
| 7 |
+
def __init__(self, agent: CodeAgent):
|
| 8 |
+
self.agent = agent
|
| 9 |
+
|
| 10 |
+
def process_query(self, query: str) -> str:
|
| 11 |
+
try:
|
| 12 |
+
response = self.agent.run(query)
|
| 13 |
+
return response
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error processing query: {str(e)}"
|
| 16 |
+
|
| 17 |
+
def launch(self,
|
| 18 |
+
server_name: Optional[str] = None,
|
| 19 |
+
server_port: Optional[int] = None,
|
| 20 |
+
share: bool = False):
|
| 21 |
+
|
| 22 |
+
# Create the interface
|
| 23 |
+
with gr.Blocks(title="Smart Web Analyzer Plus") as demo:
|
| 24 |
+
gr.Markdown("# π Smart Web Analyzer Plus")
|
| 25 |
+
gr.Markdown("Analyze web content using AI to extract summaries, determine sentiment, and identify topics.")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
with gr.Column(scale=3):
|
| 29 |
+
url_input = gr.Textbox(
|
| 30 |
+
label="Enter URL",
|
| 31 |
+
placeholder="https://example.com",
|
| 32 |
+
show_label=True
|
| 33 |
+
)
|
| 34 |
+
with gr.Column(scale=2):
|
| 35 |
+
analysis_types = gr.CheckboxGroup(
|
| 36 |
+
choices=["summarize", "sentiment", "topics"],
|
| 37 |
+
label="Analysis Types",
|
| 38 |
+
value=["summarize"],
|
| 39 |
+
show_label=True
|
| 40 |
+
)
|
| 41 |
+
with gr.Column(scale=1):
|
| 42 |
+
analyze_btn = gr.Button(
|
| 43 |
+
"Analyze",
|
| 44 |
+
variant="primary"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Output display
|
| 48 |
+
with gr.Tabs() as tabs:
|
| 49 |
+
with gr.Tab("π Clean Text"):
|
| 50 |
+
clean_text_output = gr.Markdown()
|
| 51 |
+
with gr.Tab("π Summary"):
|
| 52 |
+
summary_output = gr.Markdown()
|
| 53 |
+
with gr.Tab("π Sentiment"):
|
| 54 |
+
sentiment_output = gr.Markdown()
|
| 55 |
+
with gr.Tab("π Topics"):
|
| 56 |
+
topics_output = gr.Markdown()
|
| 57 |
+
|
| 58 |
+
# Loading indicator
|
| 59 |
+
status = gr.Markdown(visible=False)
|
| 60 |
+
|
| 61 |
+
# Examples
|
| 62 |
+
gr.Examples(
|
| 63 |
+
examples=[
|
| 64 |
+
["https://www.bbc.com/news/technology-67881954", ["summarize", "sentiment"]],
|
| 65 |
+
["https://arxiv.org/html/2312.17296v1", ["topics", "summarize"]]
|
| 66 |
+
],
|
| 67 |
+
inputs=[url_input, analysis_types],
|
| 68 |
+
label="Try these examples"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
def create_analysis_prompt(url: str, types: list) -> str:
|
| 72 |
+
type_str = ", ".join(types)
|
| 73 |
+
return f"Analyze the content at {url} and provide {type_str} analysis."
|
| 74 |
+
|
| 75 |
+
def on_analyze_start():
|
| 76 |
+
return gr.update(value="β³ Analysis in progress...", visible=True)
|
| 77 |
+
|
| 78 |
+
def on_analyze_end():
|
| 79 |
+
return gr.update(value="", visible=False)
|
| 80 |
+
|
| 81 |
+
# Event handlers
|
| 82 |
+
analyze_btn.click(
|
| 83 |
+
fn=on_analyze_start,
|
| 84 |
+
outputs=[status]
|
| 85 |
+
).then(
|
| 86 |
+
fn=lambda url, types: self.process_query(create_analysis_prompt(url, types)),
|
| 87 |
+
inputs=[url_input, analysis_types],
|
| 88 |
+
outputs=[clean_text_output] # The agent will format the output appropriately
|
| 89 |
+
).then(
|
| 90 |
+
fn=on_analyze_end,
|
| 91 |
+
outputs=[status]
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
# Launch the interface
|
| 95 |
+
demo.launch(
|
| 96 |
+
server_name=server_name,
|
| 97 |
+
server_port=server_port,
|
| 98 |
+
share=share
|
| 99 |
+
)
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ smolagents
|
|
| 2 |
gradio
|
| 3 |
requests
|
| 4 |
pytz
|
| 5 |
-
pyyaml
|
|
|
|
|
|
| 2 |
gradio
|
| 3 |
requests
|
| 4 |
pytz
|
| 5 |
+
pyyaml
|
| 6 |
+
duckduckgo-search
|