Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,20 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
-
client = InferenceClient(
|
| 6 |
-
"mistralai/Mistral-7B-Instruct-v0.1"
|
| 7 |
-
)
|
| 8 |
|
| 9 |
class GroupTherapyAgent:
|
| 10 |
-
def __init__(self, client
|
| 11 |
self.client = client
|
| 12 |
-
self.tokenizer = tokenizer
|
| 13 |
self.max_length = 64
|
| 14 |
|
| 15 |
def get_response(self, user_question):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
response = self.tokenizer.decode(response_ids, skip_special_tokens=True)
|
| 19 |
-
return response
|
| 20 |
-
|
| 21 |
-
def generate_response(self, input_ids):
|
| 22 |
-
output = self.client.generate(input_ids, max_length=self.max_length, num_beams=4)
|
| 23 |
-
return output
|
| 24 |
|
| 25 |
class GroupTherapyApplication:
|
| 26 |
-
def __init__(self, client
|
| 27 |
-
self.agents = [GroupTherapyAgent(client
|
| 28 |
|
| 29 |
def get_advice(self, user_question):
|
| 30 |
advice = []
|
|
@@ -33,23 +23,10 @@ class GroupTherapyApplication:
|
|
| 33 |
advice.append(response)
|
| 34 |
return advice
|
| 35 |
|
| 36 |
-
app = GroupTherapyApplication(client
|
| 37 |
advice = app.get_advice("I feel anxious when I have to speak in front of a group of people.")
|
| 38 |
print(f"Advice from Agents:\n{advice}")
|
| 39 |
|
| 40 |
-
# Assuming the backend functionality is defined in a separate file, say 'therapy_app.py'
|
| 41 |
-
# from therapy_app import GroupTherapyApplication
|
| 42 |
-
|
| 43 |
-
# Temporary function to simulate responses (replace with real model interactions later)
|
| 44 |
-
def get_simulated_responses(question):
|
| 45 |
-
# These are just placeholder responses. Replace this with calls to your model.
|
| 46 |
-
return [
|
| 47 |
-
f"Agent 1 says: Regarding your concern, '{question}', I think...",
|
| 48 |
-
f"Agent 2 says: In response to '{question}', my advice would be...",
|
| 49 |
-
f"Agent 3 says: I understand that '{question}' can be challenging. My suggestion...",
|
| 50 |
-
f"Agent 4 says: From my experience, '{question}' is often addressed by..."
|
| 51 |
-
]
|
| 52 |
-
|
| 53 |
# Streamlit App Layout
|
| 54 |
st.title("Group Therapy Session App")
|
| 55 |
|
|
@@ -59,8 +36,8 @@ user_question = st.text_area("Enter your question or share your experience:", he
|
|
| 59 |
# Button to submit question
|
| 60 |
if st.button("Get Advice"):
|
| 61 |
if user_question:
|
| 62 |
-
#
|
| 63 |
-
responses =
|
| 64 |
|
| 65 |
for idx, response in enumerate(responses, start=1):
|
| 66 |
st.markdown(f"**Agent {idx}:** {response}")
|
|
@@ -69,4 +46,4 @@ if st.button("Get Advice"):
|
|
| 69 |
|
| 70 |
# Footer
|
| 71 |
st.markdown("---")
|
| 72 |
-
st.caption("Disclaimer: The responses are simulated and for demonstration purposes only.")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
|
|
|
|
|
|
|
| 5 |
|
| 6 |
class GroupTherapyAgent:
|
| 7 |
+
def __init__(self, client):
|
| 8 |
self.client = client
|
|
|
|
| 9 |
self.max_length = 64
|
| 10 |
|
| 11 |
def get_response(self, user_question):
|
| 12 |
+
response = self.client(text=user_question, max_length=self.max_length, num_beams=4)
|
| 13 |
+
return response[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
class GroupTherapyApplication:
|
| 16 |
+
def __init__(self, client):
|
| 17 |
+
self.agents = [GroupTherapyAgent(client) for _ in range(4)]
|
| 18 |
|
| 19 |
def get_advice(self, user_question):
|
| 20 |
advice = []
|
|
|
|
| 23 |
advice.append(response)
|
| 24 |
return advice
|
| 25 |
|
| 26 |
+
app = GroupTherapyApplication(client)
|
| 27 |
advice = app.get_advice("I feel anxious when I have to speak in front of a group of people.")
|
| 28 |
print(f"Advice from Agents:\n{advice}")
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# Streamlit App Layout
|
| 31 |
st.title("Group Therapy Session App")
|
| 32 |
|
|
|
|
| 36 |
# Button to submit question
|
| 37 |
if st.button("Get Advice"):
|
| 38 |
if user_question:
|
| 39 |
+
# Call to the GroupTherapyApplication to get real responses
|
| 40 |
+
responses = app.get_advice(user_question)
|
| 41 |
|
| 42 |
for idx, response in enumerate(responses, start=1):
|
| 43 |
st.markdown(f"**Agent {idx}:** {response}")
|
|
|
|
| 46 |
|
| 47 |
# Footer
|
| 48 |
st.markdown("---")
|
| 49 |
+
st.caption("Disclaimer: The responses are simulated and for demonstration purposes only.")
|