zee2221 commited on
Commit
040aff1
·
1 Parent(s): 7f61a17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py CHANGED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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."
12
+
13
+ # Set up OpenAI API parameters
14
+ model_engine = "text-davinci-002"
15
+ max_tokens = 1048
16
+ temperature = 0.7
17
+
18
+ # Generate the presentation content using OpenAI's GPT-3 API
19
+ response = openai.Completion.create(
20
+ engine=model_engine,
21
+ prompt=prompt,
22
+ max_tokens=max_tokens,
23
+ temperature=temperature
24
+ )
25
+
26
+ return response.choices[0].text
27
+
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"
35
+
36
+ # Send a request to the text-to-speech API
37
+ headers = {
38
+ "api-key": api_key,
39
+ "voice": voice,
40
+ "speed": speed
41
+ }
42
+ data = {"text": text}
43
+ response = requests.post(api_url, headers=headers, json=data)
44
+
45
+ # Convert the response audio to a playable format
46
+ audio_bytes = BytesIO(response.content)
47
+ audio_segment = AudioSegment.from_file(audio_bytes.getvalue(), format="mp3")
48
+ audio_segment.export("presentation_audio.mp3", format="mp3")
49
+
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()