salomonsky commited on
Commit
84c807e
1 Parent(s): edf996c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -24
app.py CHANGED
@@ -1,12 +1,26 @@
1
  import os
2
  import openai
3
- import gradio as gr
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 de hoy es:"
12
  response = openai.Completion.create(
@@ -46,26 +60,5 @@ def generate_output(name, horoscope_type):
46
  return output_video_path, None
47
  return None, "No se pudo generar el video"
48
 
49
- name_input = gr.inputs.Textbox(lines=1, placeholder="Escribe tu Nombre Completo")
50
- horoscope_type_radio = gr.inputs.Radio(["Egipcio", "Griego", "Maya", "Chino", "Celta"], label=None)
51
- output = gr.outputs.Video(label=None)
52
-
53
- def generate_and_display_output(name, horoscope_type):
54
- video_path, error_message = generate_output(name, horoscope_type)
55
- if error_message:
56
- print(f"Error: {error_message}")
57
- else:
58
- return video_path
59
-
60
- iface = gr.Interface(
61
- fn=generate_and_display_output,
62
- inputs=[name_input, horoscope_type_radio],
63
- outputs=output,
64
- title="Hor贸scopo con Inteligencia Artificial v2.1",
65
- description="Ingresa tu nombre y selecciona el tipo de hor贸scopo.",
66
- layout="vertical",
67
- theme="dark",
68
- **{"title_image": "https://img.freepik.com/fotos-premium/fondo-estrellado-negro-universo-noche-cielo-espacio-exterior-galaxia-campo-estelar-fondo-espacio-infinito-nebulosas-estrellas_372999-413.jpg"}
69
- )
70
-
71
- iface.launch()
 
1
  import os
2
  import openai
 
3
  import subprocess
4
  from gtts import gTTS
5
  from pydub import AudioSegment
6
+ from flask import Flask, render_template, request
7
 
8
  openai.api_key = os.environ.get("openai_api_key")
9
 
10
+ app = Flask(__name__)
11
+
12
+ @app.route("/", methods=["GET", "POST"])
13
+ def index():
14
+ if request.method == "POST":
15
+ name = request.form["name"]
16
+ horoscope_type = request.form["horoscope_type"]
17
+ video_path, error_message = generate_output(name, horoscope_type)
18
+ if error_message:
19
+ return render_template("index.html", error_message=error_message)
20
+ else:
21
+ return render_template("index.html", video_path=video_path)
22
+ return render_template("index.html")
23
+
24
  def generate_output(name, horoscope_type):
25
  prompt = f"{name}, tu hor贸scopo {horoscope_type} y or谩culo de hoy es:"
26
  response = openai.Completion.create(
 
60
  return output_video_path, None
61
  return None, "No se pudo generar el video"
62
 
63
+ if __name__ == "__main__":
64
+ app.run()