Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 5 |
+
|
| 6 |
+
def format_prompt(agent_id, message):
|
| 7 |
+
return f"<s><Agent {agent_id}>[INST] {message} [/INST]"
|
| 8 |
+
|
| 9 |
+
def generate_response(agent_id, message):
|
| 10 |
+
formatted_prompt = format_prompt(agent_id, message)
|
| 11 |
+
response = client.text_generation(formatted_prompt, stream=False)
|
| 12 |
+
return response['generated_text']
|
| 13 |
+
|
| 14 |
+
def generate_group_therapy_responses(message):
|
| 15 |
+
responses = []
|
| 16 |
+
for agent_id in range(1, 5): # Four agents
|
| 17 |
+
agent_response = generate_response(agent_id, message)
|
| 18 |
+
responses.append(f"Agent {agent_id}: {agent_response}")
|
| 19 |
+
return responses
|
| 20 |
+
|
| 21 |
+
st.title("Group Therapy Simulation")
|
| 22 |
+
st.write("Ask a question and receive perspectives from four different agents.")
|
| 23 |
+
|
| 24 |
+
user_question = st.text_input("Your Question:")
|
| 25 |
+
|
| 26 |
+
if st.button("Get Responses"):
|
| 27 |
+
if user_question:
|
| 28 |
+
responses = generate_group_therapy_responses(user_question)
|
| 29 |
+
for response in responses:
|
| 30 |
+
st.write(response)
|
| 31 |
+
else:
|
| 32 |
+
st.write("Please enter a question.")
|