Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
@@ -1,123 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import json
|
3 |
-
import os
|
4 |
-
import shutil
|
5 |
-
from kalbetojai_analize import analizuoti_kalbetojus
|
6 |
-
from kalbos_nustatymas import transcribe_text, transcribe_text_wav2vec
|
7 |
-
from ataskaita import sugeneruoti_ataskaita
|
8 |
-
from filtravimas import filtruoti_audio
|
9 |
-
|
10 |
-
def gaunam_demo_failus():
|
11 |
-
folder = "demo"
|
12 |
-
if not os.path.exists(folder):
|
13 |
-
return []
|
14 |
-
return [os.path.join(folder, f) for f in os.listdir(folder) if f.endswith(".wav")]
|
15 |
-
|
16 |
-
def naudoti_demo_faila(kelias):
|
17 |
-
return kelias
|
18 |
-
|
19 |
-
def filtruoti_ir_issaugoti(wav_failas, metodas):
|
20 |
-
if wav_failas is None:
|
21 |
-
return "⚠️ Nėra failo."
|
22 |
-
if metodas != "Nefiltruoti":
|
23 |
-
print(f"🎚️ Filtruojama su: {metodas}")
|
24 |
-
filtruoti_audio(wav_failas, metodas)
|
25 |
-
return "✅ Įrašas sėkmingai išfiltruotas."
|
26 |
-
else:
|
27 |
-
print("🔎 Filtravimas praleistas – kopijuojamas originalas.")
|
28 |
-
shutil.copy(wav_failas, "/tmp/ivestis.wav")
|
29 |
-
return "✅ Įrašas nukopijuotas be filtravimo."
|
30 |
-
|
31 |
-
def analizuoti_ir_issaugoti(modelis):
|
32 |
-
# Palaikomi abu keliai
|
33 |
-
failas_kandidatas = None
|
34 |
-
if os.path.exists("/tmp/ivestis.wav"):
|
35 |
-
failas_kandidatas = "/tmp/ivestis.wav"
|
36 |
-
elif os.path.exists("temp_filtered/ivestis.wav"):
|
37 |
-
failas_kandidatas = "temp_filtered/ivestis.wav"
|
38 |
-
else:
|
39 |
-
return "⚠️ Pirma įkelkite arba filtruokite įrašą."
|
40 |
-
|
41 |
-
tekstas_ataskaitai, _, segmentai = analizuoti_kalbetojus(modelis, failas=failas_kandidatas)
|
42 |
-
|
43 |
-
os.makedirs("rezultatai", exist_ok=True)
|
44 |
-
failas = os.path.join("rezultatai", f"{modelis.lower()}.json")
|
45 |
-
with open(failas, "w", encoding="utf-8") as f:
|
46 |
-
json.dump({
|
47 |
-
"modelis": modelis,
|
48 |
-
"segmentai": segmentai
|
49 |
-
}, f, ensure_ascii=False, indent=2)
|
50 |
-
|
51 |
-
tekstas = ""
|
52 |
-
for s in segmentai:
|
53 |
-
tekstas += f"🧑 Kalbėtojas {s['kalbetojas']} – {s['kalba']}\n"
|
54 |
-
tekstas += f"💬 '{s['tekstas']}'\n"
|
55 |
-
tekstas += f"⏱️ Trukmė: {s['trukme']} s\n\n"
|
56 |
-
|
57 |
-
tekstas += "\n" + tekstas_ataskaitai
|
58 |
-
return tekstas
|
59 |
-
|
60 |
-
def gauti_filtruota_faila():
|
61 |
-
kelias = "temp_filtered/ivestis.wav"
|
62 |
-
if os.path.exists(kelias):
|
63 |
-
return kelias
|
64 |
-
elif os.path.exists("/tmp/ivestis.wav"):
|
65 |
-
return "/tmp/ivestis.wav"
|
66 |
-
else:
|
67 |
-
return None
|
68 |
-
|
69 |
-
def gauti_json_faila(modelis):
|
70 |
-
failas = os.path.join("rezultatai", f"{modelis.lower()}.json")
|
71 |
-
if os.path.exists(failas):
|
72 |
-
return failas
|
73 |
-
return None
|
74 |
-
|
75 |
-
with gr.Blocks() as demo:
|
76 |
-
gr.Markdown("## 🎤 Kalbėtojų analizė + triukšmo šalinimas + ataskaita")
|
77 |
-
|
78 |
-
with gr.Tab("1. 📦 Kalbėtojų analizė"):
|
79 |
-
with gr.Row():
|
80 |
-
demo_dropdown = gr.Dropdown(
|
81 |
-
label="📁 Pasirinkite pavyzdinį .wav failą",
|
82 |
-
choices=gaunam_demo_failus()
|
83 |
-
)
|
84 |
-
pasirinktas_failas = gr.Audio(type="filepath", label="🔊 Pasirinktas failas")
|
85 |
-
ikelti_btn = gr.Button("📥 Įkelti pasirinktą failą")
|
86 |
-
ikelti_btn.click(fn=naudoti_demo_faila, inputs=[demo_dropdown], outputs=pasirinktas_failas)
|
87 |
-
|
88 |
-
with gr.Row():
|
89 |
-
filtravimo_selector = gr.Dropdown(
|
90 |
-
label="🎚️ Filtravimo metodas",
|
91 |
-
choices=["Nefiltruoti", "Denoiser", "Wave-U-Net", "Noisereduce"],
|
92 |
-
value="Nefiltruoti"
|
93 |
-
)
|
94 |
-
filtruoti_output = gr.Textbox(label="📎 Filtravimo būsena")
|
95 |
-
filtruoti_btn = gr.Button("📀 Filtruoti įrašą")
|
96 |
-
filtruoti_btn.click(
|
97 |
-
fn=filtruoti_ir_issaugoti,
|
98 |
-
inputs=[pasirinktas_failas, filtravimo_selector],
|
99 |
-
outputs=filtruoti_output
|
100 |
-
)
|
101 |
-
|
102 |
-
with gr.Row():
|
103 |
-
model_selector = gr.Radio(["Whisper", "Wav2Vec2"], value="Whisper", label="📊 Kalbos atpažinimo modelis")
|
104 |
-
analizės_output = gr.Textbox(label="📜 Rezultatai", lines=20)
|
105 |
-
analizės_btn = gr.Button("▶️ Analizuoti kalbėtojus")
|
106 |
-
analizės_btn.click(
|
107 |
-
fn=analizuoti_ir_issaugoti,
|
108 |
-
inputs=[model_selector],
|
109 |
-
outputs=analizės_output
|
110 |
-
)
|
111 |
-
|
112 |
-
rodyti_filtruota_btn = gr.Button("📥 Parsisiųsti .wav failą")
|
113 |
-
filtruotas_failas_output = gr.File(label="⬇️ Parsisiųsti")
|
114 |
-
rodyti_filtruota_btn.click(fn=gauti_filtruota_faila, outputs=filtruotas_failas_output)
|
115 |
-
|
116 |
-
with gr.Tab("3. 📊 Ataskaita ir Atsisiuntimas"):
|
117 |
-
with gr.Row():
|
118 |
-
report_model = gr.Radio(["Whisper", "Wav2Vec2"], value="Whisper", label="📁 Pasirinkite modelį")
|
119 |
-
failas_output = gr.File(label="⬇️ Parsisiųsti JSON")
|
120 |
-
atsiuntimo_btn = gr.Button("📥 Atsisiųsti JSON")
|
121 |
-
atsiuntimo_btn.click(fn=gauti_json_faila, inputs=[report_model], outputs=failas_output)
|
122 |
-
|
123 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|