Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from smart_web_analyzer import WebAnalyzer | |
| analyzer = WebAnalyzer() | |
| def format_results(results: dict) -> dict: | |
| """Format analysis results for Gradio tabs""" | |
| outputs = {} | |
| if 'error' in results: | |
| return {"π Error": f"β {results['error']}"} | |
| outputs["π Clean Text"] = results.get('clean_text', 'No text extracted') | |
| if 'summary' in results: | |
| outputs["π Summary"] = f"**AI Summary:**\n{results['summary']}" | |
| if 'sentiment' in results: | |
| outputs["π Sentiment"] = f"**Sentiment Score:**\n{results['sentiment']}" | |
| if 'topics' in results: | |
| topics = "\n".join([f"- **{k}**: {v:.2f}" for k,v in results['topics'].items()]) | |
| outputs["π Topics"] = f"**Detected Topics:**\n{topics}" | |
| return outputs | |
| with gr.Blocks(title="Smart Web Analyzer Plus") as demo: | |
| gr.Markdown("# π Smart Web Analyzer Plus") | |
| with gr.Row(): | |
| url_input = gr.Textbox(label="Enter URL", placeholder="https://example.com") | |
| modes = gr.CheckboxGroup(["summarize", "sentiment", "topics"], | |
| label="Analysis Types") | |
| submit_btn = gr.Button("Analyze", variant="primary") | |
| with gr.Tabs(): | |
| with gr.Tab("π Clean Text"): | |
| clean_text = gr.Markdown() | |
| with gr.Tab("π Summary"): | |
| summary = gr.Markdown() | |
| with gr.Tab("π Sentiment"): | |
| sentiment = gr.Markdown() | |
| with gr.Tab("π Topics"): | |
| topics = gr.Markdown() | |
| examples = gr.Examples( | |
| examples=[ | |
| ["https://www.bbc.com/news/technology-67881954", ["summarize", "sentiment"]], | |
| ["https://arxiv.org/html/2312.17296v1", ["topics", "summarize"]] | |
| ], | |
| inputs=[url_input, modes] | |
| ) | |
| submit_btn.click( | |
| fn=lambda url, m: format_results(analyzer.analyze(url, m)), | |
| inputs=[url_input, modes], | |
| outputs=[clean_text, summary, sentiment, topics] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |