Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# streamlit_app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
st.title("Hugging Face Flask API Connector")
|
| 6 |
+
|
| 7 |
+
user_input = st.text_input("Enter text to send to Flask API:")
|
| 8 |
+
|
| 9 |
+
if st.button("Send to API"):
|
| 10 |
+
if user_input:
|
| 11 |
+
api_url = "https://HarishMaths-Backend.hf.space/predict" # Replace with your actual URL
|
| 12 |
+
payload = {"text": user_input}
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
response = requests.post(api_url, json=payload)
|
| 16 |
+
if response.status_code == 200:
|
| 17 |
+
result = response.json()
|
| 18 |
+
st.success(f"Prediction: {result['prediction']}")
|
| 19 |
+
else:
|
| 20 |
+
st.error(f"API Error: {response.status_code}")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
st.error(f"Request failed: {e}")
|