hardik-kanzariya commited on
Commit
9ad20d9
1 Parent(s): ea1035b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -37
app.py CHANGED
@@ -53,46 +53,46 @@ 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)
76
-
77
  # Streamlit UI
78
  st.title("Sentiment Analysis")
 
79
 
80
- # Use st.query_params to get the 'text' parameter from the URL
81
- query_text = st.query_params.get("text", [""])[0] # Accessing 'text' from query params
 
 
 
 
82
 
83
- if query_text:
84
- # If text is passed in the URL, process it
85
- prediction, confidence_score = getPrediction(query_text)
86
- st.json({
87
  "prediction": getSentiment(prediction) + " Statement",
88
  "confidence": f"{confidence_score * 100:.2f}%"
89
- })
90
- else:
91
- # Normal Streamlit app interface for manual text entry
92
- input_text = st.text_area("Enter Text for Sentiment Analysis")
93
- if input_text:
94
- prediction, confidence_score = getPrediction(input_text)
95
- st.json({
96
- "prediction": getSentiment(prediction) + " Statement",
97
- "confidence": f"{confidence_score * 100:.2f}%"
98
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.experimental_set_query_params(api_predict=api_predict)
76
+
77
+ # # Streamlit UI
78
+ # st.title("Sentiment Analysis")
79
+
80
+ # # Use st.query_params to get the 'text' parameter from the URL
81
+ # query_text = st.query_params.get("text", [""])[0] # Accessing 'text' from query params
82
+
83
+ # if query_text:
84
+ # # If text is passed in the URL, process it
85
+ # prediction, confidence_score = getPrediction(query_text)
86
+ # st.json({
87
+ # "prediction": getSentiment(prediction) + " Statement",
88
+ # "confidence": f"{confidence_score * 100:.2f}%"
89
+ # })
90
+ # else:
91
+ # # Normal Streamlit app interface for manual text entry
92
+ # input_text = st.text_area("Enter Text for Sentiment Analysis")
93
+ # if input_text:
94
+ # prediction, confidence_score = getPrediction(input_text)
95
+ # st.json({
96
+ # "prediction": getSentiment(prediction) + " Statement",
97
+ # "confidence": f"{confidence_score * 100:.2f}%"
98
+ # })