Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,28 +22,35 @@ with gr.Blocks(theme=gr.themes.Ocean(primary_hue="pink", neutral_hue="indigo", f
|
|
22 |
button = gr.Button("Describir", variant="primary")
|
23 |
clear = gr.Button("Borrar")
|
24 |
output = gr.Textbox(label="Resumen")
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def describir(url):
|
27 |
raw_image = Image.open(requests.get(url, stream=True).raw).convert('RGB')
|
28 |
inputs = processor(raw_image, return_tensors="pt").to("cpu")
|
29 |
out = model.generate(**inputs)
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
|
40 |
-
|
41 |
-
wav, rate = TTSHubInterface.get_prediction(task, ble, generator, sample)
|
42 |
-
ipd.Audio(wav, rate=rate)
|
43 |
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
button.click(describir, [textbox], output)
|
|
|
48 |
|
49 |
demo.launch(debug=True)
|
|
|
22 |
button = gr.Button("Describir", variant="primary")
|
23 |
clear = gr.Button("Borrar")
|
24 |
output = gr.Textbox(label="Resumen")
|
25 |
+
with gr.Row():
|
26 |
+
button2 = gr.Button("Leer", variant="primary")
|
27 |
+
clear = gr.Button("Borrar")
|
28 |
+
output2 = gr.Audio(label="Audio")
|
29 |
|
30 |
def describir(url):
|
31 |
raw_image = Image.open(requests.get(url, stream=True).raw).convert('RGB')
|
32 |
inputs = processor(raw_image, return_tensors="pt").to("cpu")
|
33 |
out = model.generate(**inputs)
|
34 |
+
return processor.decode(out[0], skip_special_tokens=True)
|
35 |
+
|
36 |
+
def leer(texto):
|
37 |
+
models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
|
38 |
+
"facebook/fastspeech2-en-ljspeech",
|
39 |
+
arg_overrides={"vocoder": "hifigan", "fp16": False}
|
40 |
+
)
|
41 |
+
model = models[0]
|
42 |
+
TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
|
43 |
+
generator = task.build_generator(model, cfg)
|
44 |
|
45 |
+
text = texto
|
|
|
|
|
46 |
|
47 |
+
sample = TTSHubInterface.get_model_input(task, text)
|
48 |
+
wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
|
49 |
+
ipd.Audio(wav, rate=rate)
|
50 |
+
return None
|
51 |
|
52 |
|
53 |
button.click(describir, [textbox], output)
|
54 |
+
button2.click(leer, [output], output2)
|
55 |
|
56 |
demo.launch(debug=True)
|