-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (30 loc) · 1.12 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
import pandas as pd
import requests
from io import BytesIO
# flask --app api.py run --port=5000
prediction_endpoint = "http://127.0.0.1:5000/predict"
st.title("Text Sentiment Predictor")
uploaded_file = st.file_uploader(
"Choose a CSV file for bulk prediction - Upload the file and click on Predict",
type="csv",
)
# Text input for sentiment prediction
user_input = st.text_input("Enter text and click on Predict", "")
# Prediction on single sentence
if st.button("Predict"):
if uploaded_file is not None:
file = {"file": uploaded_file}
response = requests.post(prediction_endpoint, files=file)
response_bytes = BytesIO(response.content)
response_df = pd.read_csv(response_bytes)
st.download_button(
label="Download Predictions",
data=response_bytes,
file_name="Predictions.csv",
key="result_download_button",
)
else:
response = requests.post(prediction_endpoint, data={"text": user_input})
response = response.json()
st.write(f"Predicted sentiment: {response['prediction']}")