Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
-
from
|
| 2 |
|
| 3 |
-
# Create an instance of the tool
|
| 4 |
-
sentiment_tool =
|
| 5 |
|
| 6 |
# Launch the Gradio interface
|
| 7 |
if __name__ == "__main__":
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
with gr.Blocks(title="Sentiment Analysis Tool") as demo:
|
| 11 |
-
gr.Markdown("# Sentiment Analysis Tool")
|
| 12 |
|
| 13 |
with gr.Row():
|
| 14 |
with gr.Column():
|
|
@@ -18,6 +18,12 @@ if __name__ == "__main__":
|
|
| 18 |
lines=5
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
with gr.Row():
|
| 22 |
analyze_btn = gr.Button("Analyze Sentiment")
|
| 23 |
clear_btn = gr.Button("Clear")
|
|
@@ -25,9 +31,15 @@ if __name__ == "__main__":
|
|
| 25 |
with gr.Column():
|
| 26 |
output = gr.JSON(label="Sentiment Analysis Results")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
analyze_btn.click(
|
| 29 |
-
fn=
|
| 30 |
-
inputs=text_input,
|
| 31 |
outputs=output
|
| 32 |
)
|
| 33 |
|
|
@@ -39,11 +51,13 @@ if __name__ == "__main__":
|
|
| 39 |
|
| 40 |
gr.Examples(
|
| 41 |
examples=[
|
| 42 |
-
["I love this product! It's amazing and works perfectly."],
|
| 43 |
-
["This movie was terrible. I was very disappointed."],
|
| 44 |
-
["The service was okay, but could be improved in several ways."]
|
|
|
|
|
|
|
| 45 |
],
|
| 46 |
-
inputs=text_input
|
| 47 |
)
|
| 48 |
|
| 49 |
demo.launch(share=True)
|
|
|
|
| 1 |
+
from simple_sentiment import SimpleSentimentTool
|
| 2 |
|
| 3 |
+
# Create an instance of the tool without preloading to avoid startup errors
|
| 4 |
+
sentiment_tool = SimpleSentimentTool(default_model="distilbert", preload=False)
|
| 5 |
|
| 6 |
# Launch the Gradio interface
|
| 7 |
if __name__ == "__main__":
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
with gr.Blocks(title="Sentiment Analysis Tool") as demo:
|
| 11 |
+
gr.Markdown("# Multi-Model Sentiment Analysis Tool")
|
| 12 |
|
| 13 |
with gr.Row():
|
| 14 |
with gr.Column():
|
|
|
|
| 18 |
lines=5
|
| 19 |
)
|
| 20 |
|
| 21 |
+
model_dropdown = gr.Dropdown(
|
| 22 |
+
choices=list(sentiment_tool.models.keys()),
|
| 23 |
+
value=sentiment_tool.default_model,
|
| 24 |
+
label="Select Model"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
with gr.Row():
|
| 28 |
analyze_btn = gr.Button("Analyze Sentiment")
|
| 29 |
clear_btn = gr.Button("Clear")
|
|
|
|
| 31 |
with gr.Column():
|
| 32 |
output = gr.JSON(label="Sentiment Analysis Results")
|
| 33 |
|
| 34 |
+
def analyze_with_model(text, model_key):
|
| 35 |
+
"""Call the tool's forward method directly with appropriate parameters."""
|
| 36 |
+
if not text:
|
| 37 |
+
return {"error": "Please enter some text to analyze"}
|
| 38 |
+
return sentiment_tool.forward(text, model_key)
|
| 39 |
+
|
| 40 |
analyze_btn.click(
|
| 41 |
+
fn=analyze_with_model,
|
| 42 |
+
inputs=[text_input, model_dropdown],
|
| 43 |
outputs=output
|
| 44 |
)
|
| 45 |
|
|
|
|
| 51 |
|
| 52 |
gr.Examples(
|
| 53 |
examples=[
|
| 54 |
+
["I love this product! It's amazing and works perfectly.", "distilbert"],
|
| 55 |
+
["This movie was terrible. I was very disappointed.", "distilbert"],
|
| 56 |
+
["The service was okay, but could be improved in several ways.", "distilbert"],
|
| 57 |
+
["Ce produit est vraiment excellent!", "multilingual"],
|
| 58 |
+
["Dieses Buch ist sehr interessant.", "german"]
|
| 59 |
],
|
| 60 |
+
inputs=[text_input, model_dropdown]
|
| 61 |
)
|
| 62 |
|
| 63 |
demo.launch(share=True)
|