adi-123 commited on
Commit
4d96058
1 Parent(s): 6d62309

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
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
- result_score = float(response.json()[0]['generated_text'].split('/')[0])
34
- sentiment = "positive" if result_score > 5.0 else "negative" if result_score < 5.0 else "mixed"
35
-
36
- st.write(f"Sentiment: {sentiment}")
 
 
 
 
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.")