Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,97 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
from gtts import gTTS
|
4 |
-
import requests
|
5 |
import os
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
|
10 |
-
#
|
11 |
-
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
12 |
-
|
13 |
-
# Function to generate a Trump-like response
|
14 |
def generate_response(prompt):
|
15 |
-
#
|
16 |
-
|
17 |
-
prompt,
|
18 |
-
max_length=100, # Adjust length as needed
|
19 |
-
num_return_sequences=1, # Generate only one response
|
20 |
-
temperature=0.7, # Adjust for more randomness (higher) or more coherence (lower)
|
21 |
-
)
|
22 |
-
return response[0]['generated_text']
|
23 |
-
|
24 |
-
# Uberduck API keys - Replace with your actual Uberduck API credentials
|
25 |
-
UBERDUCK_API_KEY = 'pub_wxfzmwowyumqxfnwcc' # Replace with your actual Uberduck API Key
|
26 |
-
UBERDUCK_API_SECRET = 'pk_8e4b3ad9-d26a-49ca-ac83-4ddfe4dace85' # Replace with your actual Uberduck API Secret
|
27 |
-
|
28 |
-
# Function to generate audio using Uberduck API
|
29 |
-
def generate_audio_uberduck(text):
|
30 |
-
url = "https://api.uberduck.ai/speak"
|
31 |
-
headers = {
|
32 |
-
"Accept": "application/json",
|
33 |
-
"uberduck-api-key": UBERDUCK_API_KEY,
|
34 |
-
"uberduck-api-secret": UBERDUCK_API_SECRET
|
35 |
-
}
|
36 |
-
json_data = {
|
37 |
-
"speech": text,
|
38 |
-
"voice": "donald-trump"
|
39 |
-
}
|
40 |
|
41 |
-
#
|
42 |
-
response =
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
return None
|
53 |
|
54 |
-
#
|
55 |
-
def
|
56 |
tts = gTTS(text=text, lang="en")
|
57 |
audio_path = "output.mp3"
|
58 |
tts.save(audio_path)
|
59 |
return audio_path
|
60 |
|
61 |
-
# Function to transcribe audio to text using Whisper
|
62 |
-
def transcribe_audio(file_path):
|
63 |
-
# Transcribe audio using Whisper model
|
64 |
-
transcription = transcriber(file_path)
|
65 |
-
return transcription['text']
|
66 |
-
|
67 |
# Streamlit app UI
|
68 |
-
st.title("Trump-like
|
69 |
-
st.write("
|
70 |
|
71 |
-
#
|
72 |
-
|
73 |
|
74 |
-
if
|
75 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
#
|
81 |
-
|
82 |
-
if user_input:
|
83 |
-
st.write(f"Transcribed text: {user_input}")
|
84 |
-
|
85 |
-
# Generate Trump-like response
|
86 |
-
trump_prompt = f"As a bold and confident leader, respond to: {user_input}"
|
87 |
-
trump_response = generate_response(trump_prompt)
|
88 |
-
st.write("Trump-like Assistant:", trump_response)
|
89 |
-
|
90 |
-
# Generate audio response (choose either Uberduck or gTTS)
|
91 |
-
audio_output_path = generate_audio_uberduck(trump_response) # Uberduck
|
92 |
-
# audio_output_path = generate_audio_gtts(trump_response) # gTTS as fallback
|
93 |
-
|
94 |
-
if audio_output_path:
|
95 |
-
audio_file = open(audio_output_path, "rb")
|
96 |
-
audio_bytes = audio_file.read()
|
97 |
-
st.audio(audio_bytes, format="audio/mp3")
|
|
|
1 |
import streamlit as st
|
2 |
+
import openai
|
3 |
from gtts import gTTS
|
|
|
4 |
import os
|
5 |
|
6 |
+
# Set your OpenAI API key
|
7 |
+
openai.api_key = 'your_openai_api_key' # Replace with your actual OpenAI API key
|
8 |
|
9 |
+
# Function to generate Trump-like response using OpenAI's GPT-3.5 or GPT-4
|
|
|
|
|
|
|
10 |
def generate_response(prompt):
|
11 |
+
# Craft the prompt to instruct the model to respond in a Trump-like manner
|
12 |
+
trump_prompt = f"As if you were Donald Trump, respond to the following: {prompt}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Call OpenAI API to generate response
|
15 |
+
response = openai.ChatCompletion.create(
|
16 |
+
model="gpt-3.5-turbo", # Or "gpt-4" if available in your account
|
17 |
+
messages=[
|
18 |
+
{"role": "system", "content": "You are to respond as Donald Trump would."},
|
19 |
+
{"role": "user", "content": trump_prompt}
|
20 |
+
],
|
21 |
+
max_tokens=100,
|
22 |
+
temperature=0.8
|
23 |
+
)
|
24 |
+
return response.choices[0].message['content']
|
|
|
25 |
|
26 |
+
# Function to convert text to audio using gTTS
|
27 |
+
def generate_audio(text):
|
28 |
tts = gTTS(text=text, lang="en")
|
29 |
audio_path = "output.mp3"
|
30 |
tts.save(audio_path)
|
31 |
return audio_path
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Streamlit app UI
|
34 |
+
st.title("Trump-like Text-to-Speech Assistant")
|
35 |
+
st.write("Type a question or statement, and receive a 'Trump-style' audio response!")
|
36 |
|
37 |
+
# Text input from user
|
38 |
+
user_input = st.text_input("Your message:", "Enter a message here")
|
39 |
|
40 |
+
if user_input:
|
41 |
+
# Generate Trump-like response
|
42 |
+
trump_response = generate_response(user_input)
|
43 |
+
st.write("Trump-like Assistant:", 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 |
+
# Display audio output
|
51 |
+
st.audio(audio_bytes, format="audio/mp3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|