Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import os
|
|
| 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,22 +45,35 @@ def create_summary_table(summary):
|
|
| 44 |
df = pd.DataFrame(data)
|
| 45 |
return df
|
| 46 |
|
| 47 |
-
def process_audio(
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
summary = summarize_text(text)
|
|
|
|
| 50 |
table = create_summary_table(summary)
|
|
|
|
| 51 |
return text, summary, table
|
| 52 |
|
| 53 |
with gr.Blocks() as app:
|
| 54 |
gr.Markdown("## اپلیکیشن تبدیل صوت به متن و خلاصهسازی")
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
text_output = gr.Textbox(label="متن تبدیلشده")
|
| 57 |
summary_output = gr.Textbox(label="خلاصه گزارش")
|
| 58 |
table_output = gr.DataFrame(label="جدول خلاصه")
|
| 59 |
-
|
| 60 |
-
submit_button.click(
|
| 61 |
fn=process_audio,
|
| 62 |
-
inputs=
|
| 63 |
outputs=[text_output, summary_output, table_output]
|
| 64 |
)
|
| 65 |
|
|
|
|
| 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 |
df = pd.DataFrame(data)
|
| 46 |
return df
|
| 47 |
|
| 48 |
+
def process_audio(file, progress=gr.Progress()):
|
| 49 |
+
if file is None:
|
| 50 |
+
return "خطا: فایل صوتی دریافت نشد.", "", None
|
| 51 |
+
progress(0, desc="شروع آپلود فایل...")
|
| 52 |
+
# شبیهسازی پیشرفت آپلود (برای تست)
|
| 53 |
+
for i in range(1, 11):
|
| 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)
|
| 61 |
+
progress(1.0, desc="پردازش کامل شد")
|
| 62 |
return text, summary, table
|
| 63 |
|
| 64 |
with gr.Blocks() as app:
|
| 65 |
gr.Markdown("## اپلیکیشن تبدیل صوت به متن و خلاصهسازی")
|
| 66 |
+
upload_button = gr.UploadButton(
|
| 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 |
+
upload_button.upload(
|
|
|
|
| 75 |
fn=process_audio,
|
| 76 |
+
inputs=upload_button,
|
| 77 |
outputs=[text_output, summary_output, table_output]
|
| 78 |
)
|
| 79 |
|