pittman commited on
Commit
b815115
·
verified ·
1 Parent(s): 961ba58

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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 # Add this to access environment variables
4
 
5
- # Get private token from Space secret (secure, no user input)
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 using private token
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
- response = requests.post(
73
- "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3",
74
- headers={"Authorization": f"Bearer {hf_token}"},
75
- json={"inputs": prompt}
76
- ).json()
77
- return "I am Agent-001, a SEMINAL member: " + response[0]['generated_text'].split("Response (prioritize humans):")[-1].strip()
 
 
 
 
 
 
 
 
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