Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
|
| 2 |
-
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
import openai
|
| 5 |
from gtts import gTTS
|
| 6 |
import os
|
| 7 |
-
# Set your OpenAI API key
|
| 8 |
-
openai.api_key = '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' # Replace with your actual OpenAI API key
|
| 9 |
|
| 10 |
# Set your OpenAI API key
|
| 11 |
openai.api_key = 'your_openai_api_key' # Replace with your actual OpenAI API key
|
|
@@ -15,8 +14,8 @@ def generate_response(prompt):
|
|
| 15 |
# Craft the prompt to instruct the model to respond in a Trump-like manner
|
| 16 |
trump_prompt = f"As if you were Donald Trump, respond to the following: {prompt}"
|
| 17 |
|
| 18 |
-
# Call OpenAI API to generate response
|
| 19 |
-
response = openai.
|
| 20 |
model="gpt-3.5-turbo", # Or "gpt-4" if available in your account
|
| 21 |
messages=[
|
| 22 |
{"role": "system", "content": "You are to respond as Donald Trump would."},
|
|
@@ -25,7 +24,7 @@ def generate_response(prompt):
|
|
| 25 |
max_tokens=100,
|
| 26 |
temperature=0.8
|
| 27 |
)
|
| 28 |
-
return response.choices[0]
|
| 29 |
|
| 30 |
# Function to convert text to audio using gTTS
|
| 31 |
def generate_audio(text):
|
|
@@ -41,27 +40,6 @@ st.write("Type in a question or statement, and receive a 'Trump-style' response
|
|
| 41 |
# Text input from user
|
| 42 |
user_input = st.text_input("Your message:", "Enter a message here")
|
| 43 |
|
| 44 |
-
if user_input:
|
| 45 |
-
# Generate Trump-like response
|
| 46 |
-
trump_response = generate_response(user_input)
|
| 47 |
-
st.write("Trump-like Assistant:", trump_response)
|
| 48 |
-
|
| 49 |
-
# Convert response to audio
|
| 50 |
-
audio_output_path = generate_audio(trump_response)
|
| 51 |
-
audio_file = open(audio_output_path, "rb")
|
| 52 |
-
audio_bytes = audio_file.read()
|
| 53 |
-
|
| 54 |
-
# Display audio output
|
| 55 |
-
st.audio(audio_bytes, format="audio/mp3") tts.save(audio_path)
|
| 56 |
-
return audio_path
|
| 57 |
-
|
| 58 |
-
# Streamlit app UI
|
| 59 |
-
st.title("Trump-like Text-to-Speech Assistant")
|
| 60 |
-
st.write("Type a question or statement, and receive a 'Trump-style' audio response!")
|
| 61 |
-
|
| 62 |
-
# Text input from user
|
| 63 |
-
user_input = st.text_input("Your message:", "Enter a message here")
|
| 64 |
-
|
| 65 |
if user_input:
|
| 66 |
# Generate Trump-like response
|
| 67 |
trump_response = generate_response(user_input)
|
|
|
|
| 1 |
|
| 2 |
+
# Set your OpenAI API key
|
| 3 |
+
openai.api_key = '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' # Replace with your actual OpenAI API key
|
| 4 |
import streamlit as st
|
| 5 |
import openai
|
| 6 |
from gtts import gTTS
|
| 7 |
import os
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Set your OpenAI API key
|
| 10 |
openai.api_key = 'your_openai_api_key' # Replace with your actual OpenAI API key
|
|
|
|
| 14 |
# Craft the prompt to instruct the model to respond in a Trump-like manner
|
| 15 |
trump_prompt = f"As if you were Donald Trump, respond to the following: {prompt}"
|
| 16 |
|
| 17 |
+
# Call OpenAI API to generate response using the updated format
|
| 18 |
+
response = openai.chat_completions_v1(
|
| 19 |
model="gpt-3.5-turbo", # Or "gpt-4" if available in your account
|
| 20 |
messages=[
|
| 21 |
{"role": "system", "content": "You are to respond as Donald Trump would."},
|
|
|
|
| 24 |
max_tokens=100,
|
| 25 |
temperature=0.8
|
| 26 |
)
|
| 27 |
+
return response.choices[0]['message']['content']
|
| 28 |
|
| 29 |
# Function to convert text to audio using gTTS
|
| 30 |
def generate_audio(text):
|
|
|
|
| 40 |
# Text input from user
|
| 41 |
user_input = st.text_input("Your message:", "Enter a message here")
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if user_input:
|
| 44 |
# Generate Trump-like response
|
| 45 |
trump_response = generate_response(user_input)
|