Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
from io import BytesIO
|
4 |
from pydub import AudioSegment
|
5 |
-
import requests
|
6 |
|
7 |
# Set up OpenAI API
|
8 |
-
openai.api_key = "
|
|
|
9 |
|
10 |
def generate_presentation(topic):
|
11 |
prompt = f"Please explain {topic} in the most easy and attractive way possible."
|
@@ -28,7 +29,7 @@ def generate_presentation(topic):
|
|
28 |
|
29 |
def generate_audio(text):
|
30 |
# Set up text-to-speech API parameters
|
31 |
-
api_key = "
|
32 |
api_url = "https://api.fpt.ai/hmi/tts/v5"
|
33 |
voice = "banmai"
|
34 |
speed = "0"
|
@@ -50,19 +51,29 @@ def generate_audio(text):
|
|
50 |
return audio_bytes
|
51 |
|
52 |
|
53 |
-
def
|
54 |
presentation = generate_presentation(topic)
|
55 |
audio = generate_audio(presentation)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
return presentation, audio.read()
|
59 |
|
60 |
-
# Set up Gradio interface
|
61 |
-
inputs = gr.inputs.Textbox(label="Enter the topic for your presentation:")
|
62 |
-
outputs = [
|
63 |
-
gr.outputs.Textbox(label="Presentation"),
|
64 |
-
gr.outputs.Audio(label="Presentation Audio", type="audio")
|
65 |
-
]
|
66 |
|
67 |
-
|
68 |
-
|
|
|
1 |
+
import requests
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
from io import BytesIO
|
5 |
from pydub import AudioSegment
|
|
|
6 |
|
7 |
# Set up OpenAI API
|
8 |
+
openai.api_key = "YOUR_API_KEY"
|
9 |
+
|
10 |
|
11 |
def generate_presentation(topic):
|
12 |
prompt = f"Please explain {topic} in the most easy and attractive way possible."
|
|
|
29 |
|
30 |
def generate_audio(text):
|
31 |
# Set up text-to-speech API parameters
|
32 |
+
api_key = "YOUR_API_KEY"
|
33 |
api_url = "https://api.fpt.ai/hmi/tts/v5"
|
34 |
voice = "banmai"
|
35 |
speed = "0"
|
|
|
51 |
return audio_bytes
|
52 |
|
53 |
|
54 |
+
def generate_presentation_and_audio(topic):
|
55 |
presentation = generate_presentation(topic)
|
56 |
audio = generate_audio(presentation)
|
57 |
+
return presentation, audio
|
58 |
+
|
59 |
+
|
60 |
+
def main():
|
61 |
+
title = "AICademy"
|
62 |
+
description = "Generate a presentation on any topic using GPT-3 and convert it to audio using FPT's text-to-speech API."
|
63 |
+
inputs = gr.inputs.Textbox(label="Enter the topic for your presentation:")
|
64 |
+
outputs = [
|
65 |
+
gr.outputs.Audio(label="Presentation Audio", type="numpy"),
|
66 |
+
gr.outputs.Textbox(label="Presentation Text")
|
67 |
+
]
|
68 |
+
examples = [
|
69 |
+
["What is artificial intelligence?"],
|
70 |
+
["How do black holes form?"],
|
71 |
+
["Explain the concept of quantum computing."],
|
72 |
+
]
|
73 |
+
iface = gr.Interface(fn=generate_presentation_and_audio, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
|
74 |
|
75 |
+
iface.launch()
|
|
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
if __name__ == "__main__":
|
79 |
+
main()
|