hardik-kanzariya commited on
Commit
34eb5b5
1 Parent(s): c8ffa15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -53,23 +53,43 @@ def getPrediction(input):
53
  def getSentiment(idx):
54
  return {0: "Negative", 1: "Positive", 2: "Neutral"}.get(idx, "Neutral")
55
 
56
- # Streamlit UI
57
- st.title("Sentiment Analysis")
58
- text = st.text_area("Enter Text...")
59
 
60
- if text:
61
- prediction, confidence_score = getPrediction([text]) # Modify if preprocessing is needed
62
- # Convert prediction to a human-readable format
63
- response = {"prediction": getSentiment(prediction[0]) + " Statement",
64
- "confidence": "{:.2f}".format(float(confidence_score[0] * 100)) + "%"} # Adjust as necessary for output formatting
65
- st.json(response)
 
 
 
 
 
 
 
 
 
 
66
 
67
- # Add a POST endpoint
68
- def api_predict(text):
 
 
 
69
  prediction, confidence_score = getPrediction(text)
70
- return {
71
  "prediction": getSentiment(prediction) + " Statement",
72
  "confidence": f"{confidence_score * 100:.2f}%"
73
- }
74
-
75
- st.query_params(api_predict=api_predict)
 
 
 
 
 
 
 
 
53
  def getSentiment(idx):
54
  return {0: "Negative", 1: "Positive", 2: "Neutral"}.get(idx, "Neutral")
55
 
56
+ # # Streamlit UI
57
+ # st.title("Sentiment Analysis")
58
+ # text = st.text_area("Enter Text...")
59
 
60
+ # if text:
61
+ # prediction, confidence_score = getPrediction([text]) # Modify if preprocessing is needed
62
+ # # Convert prediction to a human-readable format
63
+ # response = {"prediction": getSentiment(prediction[0]) + " Statement",
64
+ # "confidence": "{:.2f}".format(float(confidence_score[0] * 100)) + "%"} # Adjust as necessary for output formatting
65
+ # st.json(response)
66
+
67
+ # # Add a POST endpoint
68
+ # def api_predict(text):
69
+ # prediction, confidence_score = getPrediction(text)
70
+ # return {
71
+ # "prediction": getSentiment(prediction) + " Statement",
72
+ # "confidence": f"{confidence_score * 100:.2f}%"
73
+ # }
74
+
75
+ # st.query_params(api_predict=api_predict)
76
 
77
+ # Use query parameters to simulate an API call
78
+ query_params = st.experimental_get_query_params()
79
+ text = query_params.get("text", [""])[0]
80
+
81
+ if text:
82
  prediction, confidence_score = getPrediction(text)
83
+ st.write({
84
  "prediction": getSentiment(prediction) + " Statement",
85
  "confidence": f"{confidence_score * 100:.2f}%"
86
+ })
87
+ else:
88
+ # Normal Streamlit app interface
89
+ input_text = st.text_area("Enter Text for Sentiment Analysis")
90
+ if input_text:
91
+ prediction, confidence_score = getPrediction(input_text)
92
+ st.json({
93
+ "prediction": getSentiment(prediction) + " Statement",
94
+ "confidence": f"{confidence_score * 100:.2f}%"
95
+ })