Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,26 @@
|
|
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
|
6 |
from gtts import gTTS
|
|
|
7 |
import os
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
#
|
|
|
|
|
|
|
13 |
def generate_response(prompt):
|
14 |
-
# Craft the prompt to
|
15 |
-
trump_prompt = f"
|
16 |
|
17 |
-
#
|
18 |
-
response =
|
19 |
-
|
20 |
-
messages=[
|
21 |
-
{"role": "system", "content": "You are to respond as Donald Trump would."},
|
22 |
-
{"role": "user", "content": trump_prompt}
|
23 |
-
],
|
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):
|
@@ -34,7 +30,7 @@ def generate_audio(text):
|
|
34 |
return audio_path
|
35 |
|
36 |
# Streamlit app UI
|
37 |
-
st.title("Trump-like
|
38 |
st.write("Type in a question or statement, and receive a 'Trump-style' response in text and audio!")
|
39 |
|
40 |
# Text input from user
|
|
|
1 |
|
|
|
|
|
2 |
import streamlit as st
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
4 |
from gtts import gTTS
|
5 |
+
import torch
|
6 |
import os
|
7 |
|
8 |
+
# Load the pre-trained language model and tokenizer from Hugging Face
|
9 |
+
model_name = "gpt2-medium" # Replace with a specific Trump-like model if available on Hugging Face
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
12 |
|
13 |
+
# Set up a text generation pipeline
|
14 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1)
|
15 |
+
|
16 |
+
# Function to generate Trump-like response
|
17 |
def generate_response(prompt):
|
18 |
+
# Craft the prompt to encourage a Trump-like response
|
19 |
+
trump_prompt = f"Donald Trump says: {prompt}"
|
20 |
|
21 |
+
# Generate the response
|
22 |
+
response = generator(trump_prompt, max_length=100, num_return_sequences=1, temperature=0.8)
|
23 |
+
return response[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Function to convert text to audio using gTTS
|
26 |
def generate_audio(text):
|
|
|
30 |
return audio_path
|
31 |
|
32 |
# Streamlit app UI
|
33 |
+
st.title("Trump-like Chat Assistant")
|
34 |
st.write("Type in a question or statement, and receive a 'Trump-style' response in text and audio!")
|
35 |
|
36 |
# Text input from user
|