Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import os
|
|
| 6 |
import spaces
|
| 7 |
import soundfile as sf
|
| 8 |
import numpy as np
|
| 9 |
-
import time
|
| 10 |
|
| 11 |
# تنظیم کلید API از متغیر محیطی
|
| 12 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
@@ -45,16 +44,12 @@ def create_summary_table(summary):
|
|
| 45 |
df = pd.DataFrame(data)
|
| 46 |
return df
|
| 47 |
|
| 48 |
-
def process_audio(
|
| 49 |
-
if
|
| 50 |
return "خطا: فایل صوتی دریافت نشد.", "", None
|
| 51 |
-
progress(0, desc="
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
time.sleep(0.5) # شبیهسازی زمان آپلود
|
| 55 |
-
progress(i / 10, desc=f"آپلود فایل: {i*10}%")
|
| 56 |
-
text = speech_to_text(file.name)
|
| 57 |
-
progress(0.5, desc="در حال پردازش متن...")
|
| 58 |
summary = summarize_text(text)
|
| 59 |
progress(0.9, desc="ایجاد جدول خلاصه...")
|
| 60 |
table = create_summary_table(summary)
|
|
@@ -62,18 +57,15 @@ def process_audio(file, progress=gr.Progress()):
|
|
| 62 |
return text, summary, table
|
| 63 |
|
| 64 |
with gr.Blocks() as app:
|
| 65 |
-
gr.Markdown("## اپلیکیشن تبدیل صوت به متن و
|
| 66 |
-
|
| 67 |
-
label="آپلود فایل صوتی",
|
| 68 |
-
file_types=["audio", ".mp3", ".wav", ".m4a"],
|
| 69 |
-
file_count="single"
|
| 70 |
-
)
|
| 71 |
text_output = gr.Textbox(label="متن تبدیلشده")
|
| 72 |
summary_output = gr.Textbox(label="خلاصه گزارش")
|
| 73 |
table_output = gr.DataFrame(label="جدول خلاصه")
|
| 74 |
-
|
|
|
|
| 75 |
fn=process_audio,
|
| 76 |
-
inputs=
|
| 77 |
outputs=[text_output, summary_output, table_output]
|
| 78 |
)
|
| 79 |
|
|
|
|
| 6 |
import spaces
|
| 7 |
import soundfile as sf
|
| 8 |
import numpy as np
|
|
|
|
| 9 |
|
| 10 |
# تنظیم کلید API از متغیر محیطی
|
| 11 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
|
|
| 44 |
df = pd.DataFrame(data)
|
| 45 |
return df
|
| 46 |
|
| 47 |
+
def process_audio(audio_file, progress=gr.Progress()):
|
| 48 |
+
if audio_file is None:
|
| 49 |
return "خطا: فایل صوتی دریافت نشد.", "", None
|
| 50 |
+
progress(0, desc="در حال پردازش فایل صوتی...")
|
| 51 |
+
text = speech_to_text(audio_file)
|
| 52 |
+
progress(0.5, desc="در حال خلاصهسازی متن...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
summary = summarize_text(text)
|
| 54 |
progress(0.9, desc="ایجاد جدول خلاصه...")
|
| 55 |
table = create_summary_table(summary)
|
|
|
|
| 57 |
return text, summary, table
|
| 58 |
|
| 59 |
with gr.Blocks() as app:
|
| 60 |
+
gr.Markdown("## اپلیکیشن تبدیل صوت به متن و خلاصهسازی\n**توجه**: آپلود فایلهای صوتی بزرگ ممکن است چند دقیقه طول بکشد. لطفاً صبر کنید تا پردازش کامل شود.")
|
| 61 |
+
audio_input = gr.Audio(type="filepath", label="فایل صوتی را آپلود کنید (MP3، WAV، M4A)")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
text_output = gr.Textbox(label="متن تبدیلشده")
|
| 63 |
summary_output = gr.Textbox(label="خلاصه گزارش")
|
| 64 |
table_output = gr.DataFrame(label="جدول خلاصه")
|
| 65 |
+
submit_button = gr.Button("پردازش")
|
| 66 |
+
submit_button.click(
|
| 67 |
fn=process_audio,
|
| 68 |
+
inputs=audio_input,
|
| 69 |
outputs=[text_output, summary_output, table_output]
|
| 70 |
)
|
| 71 |
|