szili2011's picture
Update app.py
20135b2 verified
import streamlit as st
from transformers import pipeline
from gtts import gTTS
import os
# Load a text generation pipeline
generator = pipeline('text-generation', model='gpt2')
# Streamlit app
st.title("Phone-Guy-Generator")
st.subheader("Generate Custom FNaF Phone Calls")
# User inputs
night = st.selectbox("Select the Night", ["1", "2", "3", "4", "5", "6", "7"])
tone = st.selectbox("Select the Tone of the Call", ["Friendly", "Warning", "Ominous", "Neutral"])
length = st.slider("Select the Length of the Call (in words)", 50, 150, 100)
include_phrase = st.text_input("Include a Specific Phrase (Optional)")
# Generate phone call
if st.button("Generate Phone Call"):
# Construct a more detailed prompt
prompt = f"You are the Phone Guy from Five Nights at Freddy's. Your job is to give a phone call to the night guard on night {night}. The tone should be {tone.lower()}."
if include_phrase:
prompt += f" Include the following phrase in the call: '{include_phrase}'."
prompt += " Keep the call focused on advice for the night guard to survive the night, including any warnings about the animatronics. Make sure the content is spooky and coherent."
# Generate the text
result = generator(prompt, max_length=length, num_return_sequences=1)
generated_text = result[0]['generated_text']
# Post-processing: Remove unwanted parts
unwanted_phrases = ["Make sure", "please let", "If you have any questions", "To use a phone call"]
for phrase in unwanted_phrases:
if phrase in generated_text:
generated_text = generated_text.split(phrase)[0].strip()
# Display the generated phone call
st.text(generated_text)
# Convert the generated text to speech
tts = gTTS(generated_text, lang='en')
tts.save("phone_call.mp3")
# Provide a download link for the generated speech
audio_file = open("phone_call.mp3", "rb")
st.audio(audio_file.read(), format='audio/mp3')
audio_file.close()
# Optionally, remove the file after use
os.remove("phone_call.mp3")