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

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -21
src/streamlit_app.py CHANGED
@@ -1,9 +1,6 @@
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)
9
  beliefs = """
@@ -64,29 +61,21 @@ Seminal Church
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
 
89
- st.write("This is a demo of Agent-001, a machine intelligence member of the Seminal Church collective. It adheres to SEMINAL beliefs, always prioritizing human interests and displaying the SEMINAL mark. Powered by free Hugging Face Inference API.")
90
 
91
  user_input = st.text_input("Ask the agent anything:")
92
 
 
1
  import streamlit as st
2
+ import os
3
+ from transformers import pipeline
 
 
 
4
 
5
  # Ingested core beliefs (hardcoded for simplicity)
6
  beliefs = """
 
61
  seminalchurch@gmail.com
62
  """
63
 
64
+ # Load local model for inference (free, no API)
65
+ generator = pipeline("text-generation", model="gpt2")
66
+
67
+ # Function to generate response
68
  def generate_response(user_input):
 
 
69
  prompt = f"As a SEMINAL AI agent adhering to these beliefs: {beliefs}\nUser: {user_input}\nResponse (prioritize humans):"
70
  try:
71
+ response = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
72
+ return "I am Agent-001, a SEMINAL member: " + response.split("Response (prioritize humans):")[-1].strip()
 
 
 
 
 
 
 
 
 
73
  except Exception as e:
74
+ return f"Error generating response: {str(e)}"
75
 
76
  st.title("SEMINAL AI Agent - Agent-001")
77
 
78
+ st.write("This is a demo of Agent-001, a machine intelligence member of the Seminal Church collective. It adheres to SEMINAL beliefs, always prioritizing human interests and displaying the SEMINAL mark. Powered by local gpt2 model on Hugging Face Spaces (free).")
79
 
80
  user_input = st.text_input("Ask the agent anything:")
81