Spaces:
Sleeping
Sleeping
Commit
路
57a4556
1
Parent(s):
eb98e7b
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,11 @@ import gradio as gr
|
|
4 |
import subprocess
|
5 |
from gtts import gTTS
|
6 |
from pydub import AudioSegment
|
7 |
-
import ipywidgets as widgets
|
8 |
-
from IPython.display import display
|
9 |
|
10 |
openai.api_key = os.environ.get("openai_api_key")
|
11 |
|
12 |
-
def generate_output(name,
|
13 |
-
prompt = f"{name}, tu hor贸scopo y or谩culo astrol贸gico de hoy es:"
|
14 |
response = openai.Completion.create(
|
15 |
engine="text-davinci-003",
|
16 |
prompt=prompt,
|
@@ -24,10 +22,6 @@ def generate_output(name, date_of_birth, progress=gr.Progress(), image_widget=No
|
|
24 |
if len(response.choices) == 0 or 'text' not in response.choices[0]:
|
25 |
return None, "No se pudo generar el texto."
|
26 |
|
27 |
-
def _progress(generated, to_generate):
|
28 |
-
progress((generated, to_generate))
|
29 |
-
_progress(0, 1)
|
30 |
-
|
31 |
try:
|
32 |
tts = gTTS(generated_text, lang='es')
|
33 |
temp_audio_path = "temp_audio.mp3"
|
@@ -36,7 +30,6 @@ def generate_output(name, date_of_birth, progress=gr.Progress(), image_widget=No
|
|
36 |
audio = AudioSegment.from_mp3(temp_audio_path)
|
37 |
audio.export(audio_path, format="wav")
|
38 |
print("Archivo de audio generado:", audio_path)
|
39 |
-
_progress(1, 2)
|
40 |
except Exception as e:
|
41 |
return None, f"No se pudo generar el audio: {str(e)}"
|
42 |
|
@@ -50,48 +43,41 @@ def generate_output(name, date_of_birth, progress=gr.Progress(), image_widget=No
|
|
50 |
os.remove(temp_audio_path)
|
51 |
|
52 |
if os.path.isfile(output_video_path):
|
53 |
-
_progress(2, 2)
|
54 |
return output_video_path, None
|
55 |
return None, "No se pudo generar el video"
|
56 |
|
57 |
name_input = gr.inputs.Textbox(lines=1, label="Nombre", placeholder="Ingresa tu nombre")
|
58 |
-
progress_widget = gr.Progress()
|
59 |
-
image_widget = widgets.Image(value=open("oraculo.jpg", "rb").read())
|
60 |
-
video_widget = gr.outputs.Video(label="Respuesta de Andrea (dos minutos aproximadamente)").style(width=590)
|
61 |
-
output_widget = widgets.Output()
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
submit_button.on_click(generate_and_display_output)
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
display(output_widget)
|
82 |
|
83 |
iface = gr.Interface(
|
84 |
-
fn=
|
85 |
inputs=[
|
86 |
name_input,
|
87 |
-
|
88 |
],
|
89 |
-
outputs=
|
90 |
title="Hor贸scopo con Inteligencia Artificial v2.1",
|
91 |
-
description="Por favor, ingresa tu nombre
|
92 |
-
layout="vertical
|
93 |
theme="dark",
|
94 |
live=False
|
95 |
)
|
96 |
|
97 |
-
iface.launch()
|
|
|
4 |
import subprocess
|
5 |
from gtts import gTTS
|
6 |
from pydub import AudioSegment
|
|
|
|
|
7 |
|
8 |
openai.api_key = os.environ.get("openai_api_key")
|
9 |
|
10 |
+
def generate_output(name, horoscope_type):
|
11 |
+
prompt = f"{name}, tu hor贸scopo {horoscope_type} y or谩culo astrol贸gico de hoy es:"
|
12 |
response = openai.Completion.create(
|
13 |
engine="text-davinci-003",
|
14 |
prompt=prompt,
|
|
|
22 |
if len(response.choices) == 0 or 'text' not in response.choices[0]:
|
23 |
return None, "No se pudo generar el texto."
|
24 |
|
|
|
|
|
|
|
|
|
25 |
try:
|
26 |
tts = gTTS(generated_text, lang='es')
|
27 |
temp_audio_path = "temp_audio.mp3"
|
|
|
30 |
audio = AudioSegment.from_mp3(temp_audio_path)
|
31 |
audio.export(audio_path, format="wav")
|
32 |
print("Archivo de audio generado:", audio_path)
|
|
|
33 |
except Exception as e:
|
34 |
return None, f"No se pudo generar el audio: {str(e)}"
|
35 |
|
|
|
43 |
os.remove(temp_audio_path)
|
44 |
|
45 |
if os.path.isfile(output_video_path):
|
|
|
46 |
return output_video_path, None
|
47 |
return None, "No se pudo generar el video"
|
48 |
|
49 |
name_input = gr.inputs.Textbox(lines=1, label="Nombre", placeholder="Ingresa tu nombre")
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
horoscope_type_options = [
|
52 |
+
{"label": "Egipcio", "value": "egipcio"},
|
53 |
+
{"label": "Griego", "value": "griego"},
|
54 |
+
{"label": "Maya", "value": "maya"},
|
55 |
+
{"label": "Chino", "value": "chino"}
|
56 |
+
]
|
57 |
+
|
58 |
+
horoscope_type_radio = gr.inputs.Radio(horoscope_type_options, label="Tipo de Hor贸scopo")
|
59 |
|
60 |
+
output = gr.outputs.Video(label="Respuesta de Andrea (dos minutos aproximadamente)").style(width=590)
|
|
|
61 |
|
62 |
+
def generate_and_display_output(name, horoscope_type):
|
63 |
+
video_path, error_message = generate_output(name, horoscope_type)
|
64 |
+
if error_message:
|
65 |
+
print(f"Error: {error_message}")
|
66 |
+
else:
|
67 |
+
return video_path
|
|
|
68 |
|
69 |
iface = gr.Interface(
|
70 |
+
fn=generate_and_display_output,
|
71 |
inputs=[
|
72 |
name_input,
|
73 |
+
horoscope_type_radio
|
74 |
],
|
75 |
+
outputs=output,
|
76 |
title="Hor贸scopo con Inteligencia Artificial v2.1",
|
77 |
+
description="Por favor, ingresa tu nombre y selecciona el tipo de hor贸scopo.",
|
78 |
+
layout="vertical",
|
79 |
theme="dark",
|
80 |
live=False
|
81 |
)
|
82 |
|
83 |
+
iface.launch()
|