Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -1,6 +1,68 @@
|
|
1 |
-
from smolagents import launch_gradio_demo
|
2 |
-
from tool import SimpleTool
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
import gradio as gr
|
3 |
+
from smolagents import load_tool
|
4 |
+
import torch # Add explicit torch import
|
5 |
|
6 |
+
# Ensure CUDA is available
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
|
9 |
+
# Load the tool
|
10 |
+
web_analyzer = load_tool("MHamdan/web-analyzer", trust_remote_code=True)
|
11 |
+
|
12 |
+
def create_interface():
|
13 |
+
with gr.Blocks(title="AI Web Analyzer") as iface:
|
14 |
+
gr.Markdown("# π€ AI-Powered Web Content Analyzer")
|
15 |
+
gr.Markdown("""
|
16 |
+
## Features:
|
17 |
+
- π **Analyze**: Complete content analysis with AI summary
|
18 |
+
- π **Summarize**: AI-generated multi-section summary
|
19 |
+
- π **Sentiment**: Section-by-section sentiment analysis
|
20 |
+
- π― **Topics**: AI topic classification
|
21 |
+
""")
|
22 |
+
|
23 |
+
with gr.Row():
|
24 |
+
with gr.Column():
|
25 |
+
url_input = gr.Textbox(
|
26 |
+
label="Webpage URL",
|
27 |
+
placeholder="Enter URL to analyze..."
|
28 |
+
)
|
29 |
+
mode = gr.Dropdown(
|
30 |
+
choices=["analyze", "summarize", "sentiment", "topics"],
|
31 |
+
label="Analysis Mode",
|
32 |
+
value="analyze"
|
33 |
+
)
|
34 |
+
submit_btn = gr.Button("Analyze Content", variant="primary")
|
35 |
+
|
36 |
+
with gr.Column():
|
37 |
+
output = gr.Textbox(
|
38 |
+
label="AI Analysis Results",
|
39 |
+
lines=15
|
40 |
+
)
|
41 |
+
|
42 |
+
# Example data using artificial-intelligence-news.com
|
43 |
+
examples = [
|
44 |
+
["https://www.artificialintelligence-news.com/2024/02/14/openai-anthropic-google-white-house-red-teaming/", "analyze"],
|
45 |
+
["https://www.artificialintelligence-news.com/2024/02/13/ai-21-labs-wordtune-chatgpt-plugin/", "summarize"],
|
46 |
+
["https://www.artificialintelligence-news.com/2024/02/12/google-responds-gemini-ai-historical-images/", "sentiment"],
|
47 |
+
["https://www.artificialintelligence-news.com/2024/02/09/anthropic-claude-3-models-preview/", "topics"]
|
48 |
+
]
|
49 |
+
|
50 |
+
gr.Examples(
|
51 |
+
examples=examples,
|
52 |
+
inputs=[url_input, mode],
|
53 |
+
outputs=output,
|
54 |
+
label="Try these examples:",
|
55 |
+
cache_examples=True
|
56 |
+
)
|
57 |
+
|
58 |
+
submit_btn.click(
|
59 |
+
fn=web_analyzer,
|
60 |
+
inputs=[url_input, mode],
|
61 |
+
outputs=output
|
62 |
+
)
|
63 |
+
|
64 |
+
return iface
|
65 |
+
|
66 |
+
# Create and launch the interface
|
67 |
+
demo = create_interface()
|
68 |
+
demo.launch()
|