Ibrahimnasser commited on
Commit
0fb2f54
·
verified ·
1 Parent(s): 9cb9313

app.py created

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ st.set_page_config(page_title="🧠 Sentiment Analysis", layout="centered")
5
+ st.title("🧠 Sentiment Analysis via FastAPI")
6
+ st.write("Enter some text below and get sentiment prediction using a remote FastAPI service.")
7
+
8
+ API_URL = "https://fastapi-sentiment-analysis.onrender.com/analyze"
9
+
10
+ user_input = st.text_area("Enter your text here", height=150)
11
+
12
+ if st.button("Analyze"):
13
+ if user_input.strip() == "":
14
+ st.warning("Please enter some text.")
15
+ else:
16
+ with st.spinner("Analyzing..."):
17
+ response = requests.post(API_URL, json={"text": user_input})
18
+ if response.status_code == 200:
19
+ result = response.json()
20
+ analysis = result.get("analysis", {})
21
+ label = analysis.get("label", "Unknown")
22
+ score = analysis.get("score", 0.0)
23
+ st.success(f"**Sentiment:** {label} (Confidence: {score:.2%})")
24
+ else:
25
+ st.error(f"Failed to get a valid response from the API. Status code: {response.status_code}")
26
+
27
+ if st.button("Clear"):
28
+ st.experimental_rerun()