Spaces:
Sleeping
Sleeping
Update src/app.py.py
Browse files- src/app.py.py +38 -2
src/app.py.py
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from pathlib import Path
|
| 5 |
import subprocess
|
| 6 |
import shutil
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# --- Uploads ---
|
| 11 |
video_file = st.file_uploader("Upload video", type=["mp4", "mov"])
|
|
@@ -173,4 +188,25 @@ if st.button("Generate Preview"):
|
|
| 173 |
generate_preview()
|
| 174 |
|
| 175 |
if st.button("Go Live"):
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
from pathlib import Path
|
| 7 |
import subprocess
|
| 8 |
import shutil
|
| 9 |
|
| 10 |
+
# Gradio Space URL
|
| 11 |
+
url = 'https://your-gradio-space-url/api/endpoint' # Replace with your actual URL
|
| 12 |
+
|
| 13 |
+
# Load the write token from an environment variable
|
| 14 |
+
write_token = os.getenv('WF')
|
| 15 |
+
|
| 16 |
+
# Function to make a request
|
| 17 |
+
def make_request(data):
|
| 18 |
+
headers = {
|
| 19 |
+
'Authorization': f'Bearer {write_token}',
|
| 20 |
+
# Add any other headers required by the API
|
| 21 |
+
}
|
| 22 |
+
response = requests.post(url, json=data, headers=headers)
|
| 23 |
+
return response.json()
|
| 24 |
|
| 25 |
# --- Uploads ---
|
| 26 |
video_file = st.file_uploader("Upload video", type=["mp4", "mov"])
|
|
|
|
| 188 |
generate_preview()
|
| 189 |
|
| 190 |
if st.button("Go Live"):
|
| 191 |
+
if not video_file:
|
| 192 |
+
st.warning("Upload a video first!")
|
| 193 |
+
else:
|
| 194 |
+
st.info("Starting live stream...")
|
| 195 |
+
# Start live stream using FFmpeg
|
| 196 |
+
live_stream_url = "rtmp://your-rtmp-server/live/stream"
|
| 197 |
+
live_stream_cmd = [
|
| 198 |
+
"ffmpeg", "-re",
|
| 199 |
+
"-i", str(video_path),
|
| 200 |
+
"-c:v", "libx264",
|
| 201 |
+
"-preset", "fast",
|
| 202 |
+
"-b:v", "5M",
|
| 203 |
+
"-c:a", "aac",
|
| 204 |
+
"-f", "flv",
|
| 205 |
+
live_stream_url
|
| 206 |
+
]
|
| 207 |
+
try:
|
| 208 |
+
subprocess.Popen(live_stream_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 209 |
+
st.success("✅ Live stream started successfully!")
|
| 210 |
+
except subprocess.CalledProcessError as e:
|
| 211 |
+
st.error("❌ Failed to start live stream.")
|
| 212 |
+
st.text(e)
|