Spaces:
Sleeping
Sleeping
Jon Taylor
commited on
Commit
·
0b1146e
1
Parent(s):
4a0818c
removed old Flask server
Browse files- _server.py +0 -100
_server.py
DELETED
|
@@ -1,100 +0,0 @@
|
|
| 1 |
-
from flask import Flask, send_from_directory, jsonify, request
|
| 2 |
-
from flask_cors import CORS
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
import os
|
| 5 |
-
import requests
|
| 6 |
-
import subprocess
|
| 7 |
-
import time
|
| 8 |
-
|
| 9 |
-
from app.auth import get_meeting_token
|
| 10 |
-
|
| 11 |
-
load_dotenv()
|
| 12 |
-
|
| 13 |
-
app = Flask(__name__, static_url_path="/", static_folder="frontend/out")
|
| 14 |
-
CORS(app)
|
| 15 |
-
|
| 16 |
-
def _start_bot(bot_path, args=None):
|
| 17 |
-
daily_api_key = os.getenv("DAILY_API_KEY") or ""
|
| 18 |
-
api_path = os.getenv("DAILY_API_PATH") or "https://api.daily.co/v1"
|
| 19 |
-
|
| 20 |
-
timeout = int(os.getenv("ROOM_TIMEOUT") or os.getenv("BOT_MAX_DURATION") or 300)
|
| 21 |
-
exp = time.time() + timeout
|
| 22 |
-
|
| 23 |
-
'''
|
| 24 |
-
res = requests.post(
|
| 25 |
-
f"{api_path}/rooms",
|
| 26 |
-
headers={"Authorization": f"Bearer {daily_api_key}"},
|
| 27 |
-
json={
|
| 28 |
-
"properties": {
|
| 29 |
-
"exp": exp,
|
| 30 |
-
"enable_chat": True,
|
| 31 |
-
"enable_emoji_reactions": True,
|
| 32 |
-
"eject_at_room_exp": True,
|
| 33 |
-
"enable_prejoin_ui": False,
|
| 34 |
-
}
|
| 35 |
-
},
|
| 36 |
-
)
|
| 37 |
-
if res.status_code != 200:
|
| 38 |
-
return (
|
| 39 |
-
jsonify(
|
| 40 |
-
{
|
| 41 |
-
"error": "Unable to create room",
|
| 42 |
-
"status_code": res.status_code,
|
| 43 |
-
"text": res.text,
|
| 44 |
-
}
|
| 45 |
-
),
|
| 46 |
-
500,
|
| 47 |
-
)
|
| 48 |
-
'''
|
| 49 |
-
room_url = os.getenv("DAILY_ROOM_URL") #res.json()["url"]
|
| 50 |
-
room_name = os.getenv("DAILY_ROOM_NAME") #res.json()["name"]
|
| 51 |
-
|
| 52 |
-
meeting_token = get_meeting_token(room_url, daily_api_key, exp)
|
| 53 |
-
|
| 54 |
-
if args:
|
| 55 |
-
extra_args = " ".join([f'-{x[0]} "{x[1]}"' for x in args])
|
| 56 |
-
else:
|
| 57 |
-
extra_args = ""
|
| 58 |
-
|
| 59 |
-
proc = subprocess.Popen(
|
| 60 |
-
[
|
| 61 |
-
f"python3 {bot_path} -u {room_url} -t {meeting_token} {extra_args}"
|
| 62 |
-
],
|
| 63 |
-
shell=True,
|
| 64 |
-
bufsize=1,
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# Don't return until the bot has joined the room, but wait for at most 2 seconds.
|
| 68 |
-
attempts = 0
|
| 69 |
-
while attempts < 20:
|
| 70 |
-
time.sleep(0.1)
|
| 71 |
-
attempts += 1
|
| 72 |
-
res = requests.get(
|
| 73 |
-
f"{api_path}/rooms/{room_name}/get-session-data",
|
| 74 |
-
headers={"Authorization": f"Bearer {daily_api_key}"},
|
| 75 |
-
)
|
| 76 |
-
if res.status_code == 200:
|
| 77 |
-
break
|
| 78 |
-
print(f"Took {attempts} attempts to join room {room_name}")
|
| 79 |
-
|
| 80 |
-
return jsonify({"room_url": room_url, "token": meeting_token}), 200
|
| 81 |
-
|
| 82 |
-
# Routes
|
| 83 |
-
#@app.route("/start-bot", methods=["POST"])
|
| 84 |
-
#def start_bot():
|
| 85 |
-
# return _start_bot("./app/bot.py")
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
@app.route('/', defaults={'path': ''})
|
| 89 |
-
@app.route('/<path:path>')
|
| 90 |
-
def catch_all(path):
|
| 91 |
-
full_path = os.path.join(app.static_folder, path)
|
| 92 |
-
# Check if path is a directory and index.html exists
|
| 93 |
-
if os.path.isdir(full_path) and os.path.exists(os.path.join(full_path, 'index.html')):
|
| 94 |
-
return send_from_directory(full_path, 'index.html')
|
| 95 |
-
# Check if path.html exists
|
| 96 |
-
elif os.path.exists(full_path + '.html'):
|
| 97 |
-
return send_from_directory(app.static_folder, path + '.html')
|
| 98 |
-
# Serve index.html by default
|
| 99 |
-
else:
|
| 100 |
-
return send_from_directory(app.static_folder, 'index.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|