Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from
|
2 |
|
3 |
# Create an instance of the tool without preloading to avoid startup errors
|
4 |
sentiment_tool = SimpleSentimentTool(default_model="distilbert", preload=False)
|
@@ -34,8 +34,15 @@ if __name__ == "__main__":
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
analyze_btn.click(
|
41 |
fn=analyze_with_model,
|
|
|
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)
|
|
|
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 |
+
# The tool returns a JSON string now
|
39 |
+
json_str = sentiment_tool.forward(text, model_key)
|
40 |
+
# But we need to parse it for the Gradio JSON component
|
41 |
+
import json
|
42 |
+
try:
|
43 |
+
return json.loads(json_str)
|
44 |
+
except:
|
45 |
+
return {"error": "Failed to parse results"}
|
46 |
|
47 |
analyze_btn.click(
|
48 |
fn=analyze_with_model,
|