|
import streamlit as st |
|
import requests |
|
import os |
|
|
|
|
|
API_URL = "https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill" |
|
|
|
|
|
api_key = os.getenv('rag') |
|
|
|
headers = {"Authorization": f"Bearer {api_key}"} |
|
|
|
|
|
def query(payload): |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
return response.json() |
|
|
|
|
|
st.title("Mental Health Chatbot") |
|
st.write(""" |
|
This chatbot provides responses to mental health-related queries. |
|
Please note that this is an AI-based tool and is not a substitute for professional mental health support. |
|
""") |
|
|
|
|
|
user_input = st.text_input("How can I help you today?") |
|
|
|
if st.button("Get Response"): |
|
if user_input: |
|
|
|
output = query({"inputs": user_input}) |
|
|
|
|
|
st.write("**API Response:**", output) |
|
|
|
|
|
if 'generated_text' in output: |
|
st.write(f"**Response:** {output['generated_text']}") |
|
elif isinstance(output, list) and len(output) > 0: |
|
st.write(f"**Response:** {output[0].get('generated_text', 'No response available.')}") |
|
else: |
|
st.write("**Response:** Unable to retrieve a valid response.") |
|
else: |
|
st.write("Please enter a query to get a response.") |
|
|