Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
from gtts import gTTS
|
4 |
import torch
|
|
|
5 |
|
6 |
# Load DialoGPT model for conversational style
|
7 |
model_name = "microsoft/DialoGPT-medium"
|
@@ -32,21 +33,25 @@ st.title("Trump-like Chat Assistant")
|
|
32 |
st.write("Type in a question or statement, and receive a 'Trump-style' response in both text and audio!")
|
33 |
|
34 |
# Text input from user
|
35 |
-
user_input = st.text_input("Enter a message here")
|
36 |
|
37 |
if user_input:
|
38 |
# Generate Trump-like response
|
39 |
trump_response = generate_response(user_input)
|
40 |
|
41 |
# Display text output of the response
|
42 |
-
|
43 |
-
st.write(trump_response)
|
44 |
|
45 |
# Convert response to audio
|
46 |
audio_output_path = generate_audio(trump_response)
|
47 |
-
audio_file = open(audio_output_path, "rb")
|
48 |
-
audio_bytes = audio_file.read()
|
49 |
|
50 |
-
#
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
from gtts import gTTS
|
4 |
import torch
|
5 |
+
import os
|
6 |
|
7 |
# Load DialoGPT model for conversational style
|
8 |
model_name = "microsoft/DialoGPT-medium"
|
|
|
33 |
st.write("Type in a question or statement, and receive a 'Trump-style' response in both text and audio!")
|
34 |
|
35 |
# Text input from user
|
36 |
+
user_input = st.text_input("Your message:", "Enter a message here")
|
37 |
|
38 |
if user_input:
|
39 |
# Generate Trump-like response
|
40 |
trump_response = generate_response(user_input)
|
41 |
|
42 |
# Display text output of the response
|
43 |
+
st.subheader("Trump-like Assistant (Text Response):")
|
44 |
+
st.write(trump_response) # Show the generated text directly
|
45 |
|
46 |
# Convert response to audio
|
47 |
audio_output_path = generate_audio(trump_response)
|
|
|
|
|
48 |
|
49 |
+
# Ensure the file exists and can be played back
|
50 |
+
if os.path.exists(audio_output_path):
|
51 |
+
with open(audio_output_path, "rb") as audio_file:
|
52 |
+
audio_bytes = audio_file.read()
|
53 |
+
# Display audio output
|
54 |
+
st.subheader("Trump-like Assistant (Audio Response):")
|
55 |
+
st.audio(audio_bytes, format="audio/mp3")
|
56 |
+
else:
|
57 |
+
st.error("Failed to generate audio. Please try again.")
|