Spaces:
Sleeping
Sleeping
Initial commit with full functionality extend app1
Browse files
app.py
CHANGED
|
@@ -8,11 +8,12 @@ analyzer = WebAnalyzer()
|
|
| 8 |
def format_results(results: Dict[str, Any]) -> Dict[str, str]:
|
| 9 |
"""Format analysis results for Gradio components"""
|
| 10 |
if 'error' in results:
|
|
|
|
| 11 |
return {
|
| 12 |
-
"clean_text":
|
| 13 |
-
"summary":
|
| 14 |
-
"sentiment":
|
| 15 |
-
"topics":
|
| 16 |
}
|
| 17 |
|
| 18 |
formatted = {}
|
|
@@ -24,13 +25,13 @@ def format_results(results: Dict[str, Any]) -> Dict[str, str]:
|
|
| 24 |
# Format summary
|
| 25 |
formatted["summary"] = (
|
| 26 |
f"**AI Summary:**\n{results['summary']}"
|
| 27 |
-
if 'summary' in results else ""
|
| 28 |
)
|
| 29 |
|
| 30 |
# Format sentiment
|
| 31 |
formatted["sentiment"] = (
|
| 32 |
f"**Sentiment Analysis:**\n{results['sentiment']}"
|
| 33 |
-
if 'sentiment' in results else ""
|
| 34 |
)
|
| 35 |
|
| 36 |
# Format topics
|
|
@@ -46,7 +47,7 @@ def format_results(results: Dict[str, Any]) -> Dict[str, str]:
|
|
| 46 |
)
|
| 47 |
formatted["topics"] = f"**Detected Topics:**\n{topics_text}"
|
| 48 |
else:
|
| 49 |
-
formatted["topics"] = ""
|
| 50 |
|
| 51 |
return formatted
|
| 52 |
|
|
@@ -85,13 +86,21 @@ with gr.Blocks(title="Smart Web Analyzer Plus", theme=gr.themes.Soft()) as demo:
|
|
| 85 |
interactive=False
|
| 86 |
)
|
| 87 |
|
| 88 |
-
# Content display
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
# Loading indicator
|
| 97 |
status = gr.Markdown(visible=False)
|
|
@@ -128,10 +137,10 @@ with gr.Blocks(title="Smart Web Analyzer Plus", theme=gr.themes.Soft()) as demo:
|
|
| 128 |
fn=lambda url, m: format_results(analyzer.analyze(url, m)),
|
| 129 |
inputs=[url_input, analysis_types],
|
| 130 |
outputs=[
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
]
|
| 136 |
).then(
|
| 137 |
fn=on_analyze_end,
|
|
|
|
| 8 |
def format_results(results: Dict[str, Any]) -> Dict[str, str]:
|
| 9 |
"""Format analysis results for Gradio components"""
|
| 10 |
if 'error' in results:
|
| 11 |
+
error_msg = f"β Error: {results['error']}"
|
| 12 |
return {
|
| 13 |
+
"clean_text": error_msg,
|
| 14 |
+
"summary": error_msg,
|
| 15 |
+
"sentiment": error_msg,
|
| 16 |
+
"topics": error_msg
|
| 17 |
}
|
| 18 |
|
| 19 |
formatted = {}
|
|
|
|
| 25 |
# Format summary
|
| 26 |
formatted["summary"] = (
|
| 27 |
f"**AI Summary:**\n{results['summary']}"
|
| 28 |
+
if 'summary' in results else "No summary requested"
|
| 29 |
)
|
| 30 |
|
| 31 |
# Format sentiment
|
| 32 |
formatted["sentiment"] = (
|
| 33 |
f"**Sentiment Analysis:**\n{results['sentiment']}"
|
| 34 |
+
if 'sentiment' in results else "No sentiment analysis requested"
|
| 35 |
)
|
| 36 |
|
| 37 |
# Format topics
|
|
|
|
| 47 |
)
|
| 48 |
formatted["topics"] = f"**Detected Topics:**\n{topics_text}"
|
| 49 |
else:
|
| 50 |
+
formatted["topics"] = "No topic analysis requested"
|
| 51 |
|
| 52 |
return formatted
|
| 53 |
|
|
|
|
| 86 |
interactive=False
|
| 87 |
)
|
| 88 |
|
| 89 |
+
# Content display
|
| 90 |
+
clean_text_out = gr.Markdown(visible=True, label="Clean Text")
|
| 91 |
+
summary_out = gr.Markdown(visible=True, label="Summary")
|
| 92 |
+
sentiment_out = gr.Markdown(visible=True, label="Sentiment")
|
| 93 |
+
topics_out = gr.Markdown(visible=True, label="Topics")
|
| 94 |
+
|
| 95 |
+
with gr.Tabs() as tabs:
|
| 96 |
+
with gr.Tab("π Clean Text"):
|
| 97 |
+
clean_text_out
|
| 98 |
+
with gr.Tab("π Summary"):
|
| 99 |
+
summary_out
|
| 100 |
+
with gr.Tab("π Sentiment"):
|
| 101 |
+
sentiment_out
|
| 102 |
+
with gr.Tab("π Topics"):
|
| 103 |
+
topics_out
|
| 104 |
|
| 105 |
# Loading indicator
|
| 106 |
status = gr.Markdown(visible=False)
|
|
|
|
| 137 |
fn=lambda url, m: format_results(analyzer.analyze(url, m)),
|
| 138 |
inputs=[url_input, analysis_types],
|
| 139 |
outputs=[
|
| 140 |
+
clean_text_out,
|
| 141 |
+
summary_out,
|
| 142 |
+
sentiment_out,
|
| 143 |
+
topics_out
|
| 144 |
]
|
| 145 |
).then(
|
| 146 |
fn=on_analyze_end,
|