Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,10 +30,14 @@ if st.button("Analyze"):
|
|
30 |
response = requests.post(API_URL, headers=HEADERS, json={"inputs": prompt}, timeout=10)
|
31 |
response.raise_for_status()
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
except requests.exceptions.Timeout:
|
39 |
st.error("Request to the API timed out. Please try again.")
|
|
|
30 |
response = requests.post(API_URL, headers=HEADERS, json={"inputs": prompt}, timeout=10)
|
31 |
response.raise_for_status()
|
32 |
|
33 |
+
# Extract sentiment label from the result
|
34 |
+
result = response.json()[0]['generated_text']
|
35 |
+
sentiment = result.split()[-1].lower()
|
36 |
+
|
37 |
+
if sentiment in ("positive", "negative", "mixed"):
|
38 |
+
st.write(f"Sentiment: {sentiment}")
|
39 |
+
else:
|
40 |
+
st.write("Could not determine sentiment")
|
41 |
|
42 |
except requests.exceptions.Timeout:
|
43 |
st.error("Request to the API timed out. Please try again.")
|