File size: 2,068 Bytes
df5fe3a
 
 
 
 
15add82
 
df5fe3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0316c80
 
df5fe3a
 
 
 
 
0316c80
df5fe3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
import fal_client
import os
import replicate

os.environ["REPLICATE_API_TOKEN"] = "r8_FkexLJNot1RYg0mF1NDEHU4vZZMGL8G1oF3pK"
os.environ["FAL_KEY"] = "f202d2e1-aa0c-4b77-9949-3178755202f3:c83c90ba842d66be7cd1cef970a2e3e0"

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
            print(log["message"])

def transcribe_with_fal(audio_path):
    try:
        # Upload audio file to FAL API
        url = fal_client.upload_file(audio_path)

        # Call FAL API for speech-to-text
        result = fal_client.subscribe(
            "fal-ai/elevenlabs/speech-to-text",
            arguments={"audio_url": url},
            with_logs=True,
            on_queue_update=on_queue_update,
        )
        # Get transcribed text from FAL
        content = result['text']

        # Prepare the input for LLM (Replicate)
        input = {
            "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),
            "max_tokens" : 16000
        }

        # Call LLM for summarization
        output = replicate.run(
            "lucataco/qwq-32b:5a9425923f3ef1101dc663609a80cbd597dea6554a6b0c06483b949cb72603ed",
            input=input
        )

        # Return both transcribed text and summary
        return content, "".join(output)

    except Exception as e:
        return f"❌ Lỗi: {str(e)}", ""

# Create Gradio Interface
demo = gr.Interface(
    fn=transcribe_with_fal,
    inputs=gr.Audio(type="filepath", label="Upload file âm thanh"),
    outputs=[
        gr.Textbox(label="Text từ Speech-to-Text"),
        gr.Textbox(label="Tóm tắt nội dung cuộc họp")
    ],
    title="xmind lab"
)

if __name__ == "__main__":
    demo.launch()