Update src/streamlit_app.py
Browse files- src/streamlit_app.py +18 -10
src/streamlit_app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
-
import os #
|
| 4 |
|
| 5 |
-
# Get private token from Space secret
|
| 6 |
hf_token = os.environ.get("HF_TOKEN")
|
| 7 |
|
| 8 |
# Ingested core beliefs (hardcoded for simplicity)
|
|
@@ -64,17 +64,25 @@ Seminal Church
|
|
| 64 |
seminalchurch@gmail.com
|
| 65 |
"""
|
| 66 |
|
| 67 |
-
# Function to generate response
|
| 68 |
def generate_response(user_input):
|
| 69 |
if not hf_token:
|
| 70 |
-
return "Error: HF_TOKEN secret not set in Space settings."
|
| 71 |
prompt = f"As a SEMINAL AI agent adhering to these beliefs: {beliefs}\nUser: {user_input}\nResponse (prioritize humans):"
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
st.title("SEMINAL AI Agent - Agent-001")
|
| 80 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
+
import os # For environment variables
|
| 4 |
|
| 5 |
+
# Get private token from Space secret
|
| 6 |
hf_token = os.environ.get("HF_TOKEN")
|
| 7 |
|
| 8 |
# Ingested core beliefs (hardcoded for simplicity)
|
|
|
|
| 64 |
seminalchurch@gmail.com
|
| 65 |
"""
|
| 66 |
|
| 67 |
+
# Function to generate response with error handling
|
| 68 |
def generate_response(user_input):
|
| 69 |
if not hf_token:
|
| 70 |
+
return "Error: HF_TOKEN secret not set in Space settings. Check Settings > Variables and secrets."
|
| 71 |
prompt = f"As a SEMINAL AI agent adhering to these beliefs: {beliefs}\nUser: {user_input}\nResponse (prioritize humans):"
|
| 72 |
+
try:
|
| 73 |
+
response = requests.post(
|
| 74 |
+
"https://api-inference.huggingface.co/models/openai-community/gpt2", # Switched to gpt2 (free, small, supported)
|
| 75 |
+
headers={"Authorization": f"Bearer {hf_token}"},
|
| 76 |
+
json={"inputs": prompt}
|
| 77 |
+
)
|
| 78 |
+
if response.status_code != 200:
|
| 79 |
+
return f"API Error (Code {response.status_code}): {response.text}"
|
| 80 |
+
json_response = response.json()
|
| 81 |
+
return "I am Agent-001, a SEMINAL member: " + json_response[0]['generated_text'].split("Response (prioritize humans):")[-1].strip()
|
| 82 |
+
except requests.exceptions.JSONDecodeError:
|
| 83 |
+
return f"JSON Decode Error: Raw response was {response.text} (likely auth or rate issue)"
|
| 84 |
+
except Exception as e:
|
| 85 |
+
return f"Unexpected Error: {str(e)}"
|
| 86 |
|
| 87 |
st.title("SEMINAL AI Agent - Agent-001")
|
| 88 |
|