alex16052G commited on
Commit
008d463
verified
1 Parent(s): 6cca346

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ from f5_infer import F5TTS
4
+
5
+ # Cargar el modelo Qwen2.5-3B-Instruct
6
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-2.5B-Instruct")
7
+ model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-2.5B-Instruct", device_map="auto")
8
+
9
+ # Inicializar Spanish-F5 para s铆ntesis de voz
10
+ tts = F5TTS()
11
+
12
+ # Funci贸n principal para el flujo del chat con voz
13
+ def chat_with_voice(input_text):
14
+ # Generar respuesta con Qwen
15
+ inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
16
+ outputs = model.generate(**inputs, max_length=200)
17
+ response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+
19
+ # Convertir respuesta a audio usando Spanish-F5
20
+ audio_path = tts.generate_tts(response_text, output_path="response.wav")
21
+
22
+ return response_text, audio_path
23
+
24
+ # Interfaz de Gradio
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown("# Chat AI con Voz (Qwen y Spanish-F5)")
27
+ with gr.Row():
28
+ input_text = gr.Textbox(label="Escribe tu mensaje:", placeholder="驴C贸mo puedo ayudarte hoy?")
29
+ with gr.Row():
30
+ response_text = gr.Textbox(label="Respuesta del modelo")
31
+ response_audio = gr.Audio(label="Respuesta en voz", type="filepath")
32
+ send_btn = gr.Button("Enviar")
33
+
34
+ # Conectar eventos
35
+ send_btn.click(chat_with_voice, inputs=input_text, outputs=[response_text, response_audio])
36
+
37
+ # Ejecutar la app
38
+ demo.launch()