quangchi commited on
Commit
df5fe3a
·
verified ·
1 Parent(s): 16cac3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -59
app.py CHANGED
@@ -1,59 +1,59 @@
1
- import gradio as gr
2
- import fal_client
3
- import os
4
- import replicate
5
-
6
- os.environ["REPLICATE_API_TOKEN"] = "r8_aFOI9wuwtOp7jnruY2XxJDdczL0YU5q1p6vPR"
7
- os.environ["FAL_KEY"] = "f202d2e1-aa0c-4b77-9949-3178755202f3:c83c90ba842d66be7cd1cef970a2e3e0"
8
-
9
- def on_queue_update(update):
10
- if isinstance(update, fal_client.InProgress):
11
- for log in update.logs:
12
- print(log["message"])
13
-
14
- def transcribe_with_fal(audio_path):
15
- try:
16
- # Upload audio file to FAL API
17
- url = fal_client.upload_file(audio_path)
18
-
19
- # Call FAL API for speech-to-text
20
- result = fal_client.subscribe(
21
- "fal-ai/elevenlabs/speech-to-text",
22
- arguments={"audio_url": url},
23
- with_logs=True,
24
- on_queue_update=on_queue_update,
25
- )
26
- # Get transcribed text from FAL
27
- content = result['text']
28
-
29
- # Prepare the input for LLM (Replicate)
30
- input_data = {
31
- "prompt": "Tóm tắt nội dung dưới đây theo các mục sau: - Chủ đề chính - Các vấn đề đã được thảo luận - Các quyết định đã đưa ra - Người chịu trách nhiệm cho các hành động tiếp theo - Thời hạn hoặc thời gian dự kiến cho các hành động Nội dung cuộc họp: '{}'".format(content)
32
- }
33
-
34
- # Call LLM for summarization
35
- output = replicate.run(
36
- "lucataco/qwq-32b:5a9425923f3ef1101dc663609a80cbd597dea6554a6b0c06483b949cb72603ed",
37
- input=input_data,
38
- max_tokens=24000
39
- )
40
-
41
- # Return both transcribed text and summary
42
- return content, "".join(output)
43
-
44
- except Exception as e:
45
- return f"❌ Lỗi: {str(e)}", ""
46
-
47
- # Create Gradio Interface
48
- demo = gr.Interface(
49
- fn=transcribe_with_fal,
50
- inputs=gr.Audio(type="filepath", label="Upload file âm thanh"),
51
- outputs=[
52
- gr.Textbox(label="Text từ Speech-to-Text"),
53
- gr.Textbox(label="Tóm tắt nội dung cuộc họp")
54
- ],
55
- title="xmind lab"
56
- )
57
-
58
- if __name__ == "__main__":
59
- demo.launch()
 
1
+ import gradio as gr
2
+ import fal_client
3
+ import os
4
+ import replicate
5
+
6
+ os.environ["REPLICATE_API_TOKEN"] = "r8_aFOI9wuwtOp7jnruY2XxJDdczL0YU5q1p6vPR"
7
+ os.environ["FAL_KEY"] = "f202d2e1-aa0c-4b77-9949-3178755202f3:c83c90ba842d66be7cd1cef970a2e3e0"
8
+
9
+ def on_queue_update(update):
10
+ if isinstance(update, fal_client.InProgress):
11
+ for log in update.logs:
12
+ print(log["message"])
13
+
14
+ def transcribe_with_fal(audio_path):
15
+ try:
16
+ # Upload audio file to FAL API
17
+ url = fal_client.upload_file(audio_path)
18
+
19
+ # Call FAL API for speech-to-text
20
+ result = fal_client.subscribe(
21
+ "fal-ai/elevenlabs/speech-to-text",
22
+ arguments={"audio_url": url},
23
+ with_logs=True,
24
+ on_queue_update=on_queue_update,
25
+ )
26
+ # Get transcribed text from FAL
27
+ content = result['text']
28
+
29
+ # Prepare the input for LLM (Replicate)
30
+ input = {
31
+ "prompt": "Tóm tắt nội dung dưới đây bằng tiếng Việt theo các mục sau: - Chủ đề chính - Các vấn đề đã được thảo luận - Các quyết định đã đưa ra - Người chịu trách nhiệm cho các hành động tiếp theo - Thời hạn hoặc thời gian dự kiến cho các hành động Nội dung cuộc họp: '{}'".format(content)
32
+ }
33
+
34
+ # Call LLM for summarization
35
+ output = replicate.run(
36
+ "lucataco/qwq-32b:5a9425923f3ef1101dc663609a80cbd597dea6554a6b0c06483b949cb72603ed",
37
+ input=input,
38
+ max_tokens=120000
39
+ )
40
+
41
+ # Return both transcribed text and summary
42
+ return content, "".join(output)
43
+
44
+ except Exception as e:
45
+ return f"❌ Lỗi: {str(e)}", ""
46
+
47
+ # Create Gradio Interface
48
+ demo = gr.Interface(
49
+ fn=transcribe_with_fal,
50
+ inputs=gr.Audio(type="filepath", label="Upload file âm thanh"),
51
+ outputs=[
52
+ gr.Textbox(label="Text từ Speech-to-Text"),
53
+ gr.Textbox(label="Tóm tắt nội dung cuộc họp")
54
+ ],
55
+ title="xmind lab"
56
+ )
57
+
58
+ if __name__ == "__main__":
59
+ demo.launch()