import gradio as gr import openai from io import BytesIO from pydub import AudioSegment import requests # Set up OpenAI API openai.api_key = "YOUR_OPENAI_API_KEY" def generate_presentation(topic): prompt = f"Please explain {topic} in the most easy and attractive way possible." # Set up OpenAI API parameters model_engine = "text-davinci-002" max_tokens = 1048 temperature = 0.7 # Generate the presentation content using OpenAI's GPT-3 API response = openai.Completion.create( engine=model_engine, prompt=prompt, max_tokens=max_tokens, temperature=temperature ) return response.choices[0].text def generate_audio(text): # Set up text-to-speech API parameters api_key = "YOUR_TTS_API_KEY" api_url = "https://api.fpt.ai/hmi/tts/v5" voice = "banmai" speed = "0" # Send a request to the text-to-speech API headers = { "api-key": api_key, "voice": voice, "speed": speed } data = {"text": text} response = requests.post(api_url, headers=headers, json=data) # Convert the response audio to a playable format audio_bytes = BytesIO(response.content) audio_segment = AudioSegment.from_file(audio_bytes.getvalue(), format="mp3") audio_segment.export("presentation_audio.mp3", format="mp3") return audio_bytes def ai_presentation(topic): presentation = generate_presentation(topic) audio = generate_audio(presentation) # Return the presentation and generated audio return presentation, audio.read() # Set up Gradio interface inputs = gr.inputs.Textbox(label="Enter the topic for your presentation:") outputs = [ gr.outputs.Textbox(label="Presentation"), gr.outputs.Audio(label="Presentation Audio", type="audio") ] gr.Interface(fn=ai_presentation, inputs=inputs, outputs=outputs, title="AICademy", icon=":books:", server_port=8080).launch()