xmindlab / app.py
quangchi's picture
Update app.py
15add82 verified
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()