import gradio as gr import openai import os import requests # Load the OpenAI API key from environment variables openai.api_key = os.getenv("OPENAI_API_KEY") def translate_and_speak(text): try: # Translate text using OpenAI's ChatGPT-3.5 Turbo response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "system", "content": "try translate every prompt of word with Skibidi, rizz, ohio, edging, yapping, fanum tax, glazing, dogwater, girlboss, alpha, andrew tate, beta, baby gronk, musty, crook, quandale dingle, kai cenat, grimace, ice spice, turbulence, 3 am, lovvy dunne, mewing, mouthbreather, beta, level 1000 gyatt, caseoh, food taxer, looksmaxxing, gooner, gooning, goon"}, {"role": "user", "content": text}], max_tokens=150 ) translated_text = response['choices'][0]['message']['content'] # Generate speech from translated text using Whisper whisper_response = openai.Audio.create( model="whisper-1", input=translated_text, output_format="mp3" ) audio_url = whisper_response['url'] # Download the MP3 file from the URL response = requests.get(audio_url) if response.status_code == 200: # Save the MP3 file to a temporary path mp3_path = "/tmp/translated_audio.mp3" # Ensure this path is writable with open(mp3_path, "wb") as f: f.write(response.content) return translated_text, mp3_path else: return translated_text, "Error downloading file" except Exception as e: return f"Error: {str(e)}", "" # Create the Gradio interface interface = gr.Interface( fn=translate_and_speak, inputs=gr.Textbox(label="Enter text to translate"), outputs=[gr.Textbox(label="Translated Text"), gr.Audio(label="Listen to Translation")], title="Skibidi Translator", description="Type any phrase to translate it into a specific set of keywords and hear it spoken back." ) # Launch the interface interface.launch(share=True)