Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,13 @@ import torch
|
|
4 |
from transformers import pipeline
|
5 |
import speech_recognition as sr
|
6 |
from gtts import gTTS
|
7 |
-
from pydub import AudioSegment
|
8 |
from io import BytesIO
|
9 |
|
10 |
# Set your Hugging Face API key
|
11 |
-
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "
|
12 |
|
13 |
-
# Load the Hugging Face model
|
14 |
-
chatbot = pipeline("
|
15 |
|
16 |
# Function to get voice input using Whisper
|
17 |
def get_voice_input():
|
@@ -48,7 +47,7 @@ if st.button("Speak"):
|
|
48 |
if user_input:
|
49 |
st.write(f"You: {user_input}")
|
50 |
# Get response from the chatbot
|
51 |
-
response = chatbot(user_input)[0]['generated_text']
|
52 |
st.write(f"Bot: {response}")
|
53 |
# Generate voice response
|
54 |
audio_output = speak(response)
|
@@ -60,7 +59,7 @@ if st.button("Send"):
|
|
60 |
if user_input:
|
61 |
st.write(f"You: {user_input}")
|
62 |
# Get response from the chatbot
|
63 |
-
response = chatbot(user_input)[0]['generated_text']
|
64 |
st.write(f"Bot: {response}")
|
65 |
# Generate voice response
|
66 |
audio_output = speak(response)
|
|
|
4 |
from transformers import pipeline
|
5 |
import speech_recognition as sr
|
6 |
from gtts import gTTS
|
|
|
7 |
from io import BytesIO
|
8 |
|
9 |
# Set your Hugging Face API key
|
10 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "your_hugging_face_api_key"
|
11 |
|
12 |
+
# Load the Hugging Face model using text-generation
|
13 |
+
chatbot = pipeline("text-generation", model="thrishala/mental_health_chatbot")
|
14 |
|
15 |
# Function to get voice input using Whisper
|
16 |
def get_voice_input():
|
|
|
47 |
if user_input:
|
48 |
st.write(f"You: {user_input}")
|
49 |
# Get response from the chatbot
|
50 |
+
response = chatbot(user_input, max_length=150, num_return_sequences=1)[0]['generated_text']
|
51 |
st.write(f"Bot: {response}")
|
52 |
# Generate voice response
|
53 |
audio_output = speak(response)
|
|
|
59 |
if user_input:
|
60 |
st.write(f"You: {user_input}")
|
61 |
# Get response from the chatbot
|
62 |
+
response = chatbot(user_input, max_length=150, num_return_sequences=1)[0]['generated_text']
|
63 |
st.write(f"Bot: {response}")
|
64 |
# Generate voice response
|
65 |
audio_output = speak(response)
|