Spaces:
Runtime error
Runtime error
| from flask import Flask, jsonify, render_template, request # Tambahkan request | |
| from flask_cors import CORS | |
| import os | |
| import time | |
| from dotenv import load_dotenv | |
| from livekit import api | |
| load_dotenv() | |
| app = Flask(__name__) | |
| CORS(app) # Tambahkan ini agar CORS aktif! | |
| def home(): | |
| return render_template("index.html") | |
| def status(): | |
| return jsonify({ | |
| "status": "online", | |
| "message": "Voice Agent API Helper is running", | |
| "agent_config": { | |
| "voice": os.getenv("INWORLD_VOICE", "default"), | |
| "stt": "AssemblyAI/Deepgram" | |
| } | |
| }) | |
| def update_config(): | |
| data = request.json | |
| # Di sini Anda bisa memproses data konfigurasi yang dikirim dari UI lokal | |
| print(f"Konfigurasi diterima: {data}") | |
| return jsonify({"status": "success", "message": "Konfigurasi diperbarui"}) | |
| def get_token(): | |
| # Ambil konfigurasi dari .env | |
| lk_api_key = os.getenv("LIVEKIT_API_KEY") | |
| lk_api_secret = os.getenv("LIVEKIT_API_SECRET") | |
| # Buat Token untuk user web | |
| token = api.AccessToken(lk_api_key, lk_api_secret) \ | |
| .with_identity("web_user_" + str(int(time.time()))) \ | |
| .with_name("Web Visitor") \ | |
| .with_grants(api.VideoGrants( | |
| room_join=True, | |
| room="my-voice-room", # Harus sama dengan yang dipantau agent | |
| )) | |
| return jsonify({ | |
| "token": token.to_jwt(), | |
| "server_url": os.getenv("LIVEKIT_URL") | |
| }) | |
| if __name__ == "__main__": | |
| print("Starting Flask helper on port 7860...") | |
| # Hugging Face Spaces menggunakan port 7860 | |
| app.run(host="0.0.0.0", port=7860) |