Rajan Singh
commited on
Commit
·
d8ea436
1
Parent(s):
bc8faf9
Fixed API response and switched to environment variable
Browse files- src/streamlit_app.py +21 -12
src/streamlit_app.py
CHANGED
@@ -2,21 +2,30 @@ import streamlit as st
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
-
st.title("
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
if response.status_code == 200:
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
else:
|
22 |
st.error(f"Error {response.status_code}: {response.text}")
|
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
+
st.title("Uzmi GPT - Romantic Quote Generator")
|
6 |
|
7 |
+
# Input prompt
|
8 |
+
user_input = st.text_area("Enter your prompt:", "A romantic love quote about forever:")
|
9 |
|
10 |
+
# Button to trigger prediction
|
11 |
+
if st.button("Generate"):
|
12 |
+
API_URL = "https://api-inference.huggingface.co/models/rajan3208/uzmi-gpt"
|
13 |
+
headers = {
|
14 |
+
"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"
|
15 |
+
}
|
16 |
+
|
17 |
+
payload = {"inputs": user_input}
|
18 |
+
|
19 |
+
with st.spinner("Generating..."):
|
20 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
21 |
|
22 |
if response.status_code == 200:
|
23 |
+
try:
|
24 |
+
generated_text = response.json()[0]["generated_text"]
|
25 |
+
st.success("Generated Text:")
|
26 |
+
st.write(generated_text)
|
27 |
+
except Exception as e:
|
28 |
+
st.error("Could not parse response.")
|
29 |
+
st.json(response.json())
|
30 |
else:
|
31 |
st.error(f"Error {response.status_code}: {response.text}")
|