DangoMachoo commited on
Commit
f9a041d
·
1 Parent(s): dd7f4bb

update main code

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import torch
3
  from transformers import pipeline
4
  import os
 
5
 
6
  # ✅ ใช้ path ffmpeg ชั่วคราวเฉพาะใน local
7
  #os.environ["PATH"] += os.pathsep + r"C:\ffmpeg\ffmpeg-master-latest-win64-gpl\ffmpeg-master-latest-win64-gpl\bin"
@@ -22,7 +23,16 @@ pipe = pipeline(
22
  def transcribe_audio(audio):
23
  result = pipe(audio, generate_kwargs={"language": "<|th|>", "task": "transcribe"}, batch_size=16)
24
  text = result["text"]
25
- return text, text # ส่งทั้งแสดงบนหน้าจอ และโหลดเป็น .txt
 
 
 
 
 
 
 
 
 
26
 
27
  # ✅ UI ด้วย Gradio
28
  with gr.Blocks() as demo:
@@ -46,3 +56,4 @@ with gr.Blocks() as demo:
46
  )
47
 
48
  demo.launch()
 
 
2
  import torch
3
  from transformers import pipeline
4
  import os
5
+ import uuid
6
 
7
  # ✅ ใช้ path ffmpeg ชั่วคราวเฉพาะใน local
8
  #os.environ["PATH"] += os.pathsep + r"C:\ffmpeg\ffmpeg-master-latest-win64-gpl\ffmpeg-master-latest-win64-gpl\bin"
 
23
  def transcribe_audio(audio):
24
  result = pipe(audio, generate_kwargs={"language": "<|th|>", "task": "transcribe"}, batch_size=16)
25
  text = result["text"]
26
+
27
+ # 👇 สร้างชื่อไฟล์แบบสั้นและไม่ซ้ำ
28
+ filename = f"transcription_{uuid.uuid4().hex[:8]}.txt"
29
+ filepath = os.path.join("/tmp", filename) # หรือใช้ "./" ถ้าไม่ใช้ใน Docker
30
+
31
+ # 👇 เขียนข้อความลงไฟล์
32
+ with open(filepath, "w", encoding="utf-8") as f:
33
+ f.write(text)
34
+
35
+ return text, filepath
36
 
37
  # ✅ UI ด้วย Gradio
38
  with gr.Blocks() as demo:
 
56
  )
57
 
58
  demo.launch()
59
+