zee2221 commited on
Commit
4c3bb61
·
1 Parent(s): 4056895

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
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 = "YOUR_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 = "YOUR_TTS_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 ai_presentation(topic):
54
  presentation = generate_presentation(topic)
55
  audio = generate_audio(presentation)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- # Return the presentation and generated audio
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
- gr.Interface(fn=ai_presentation, inputs=inputs, outputs=outputs, title="AICademy",
68
- icon=":books:", server_port=8080).launch()
 
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()