Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,15 @@ import logging
|
|
| 2 |
import requests
|
| 3 |
from urllib.parse import urlparse
|
| 4 |
import subprocess
|
| 5 |
-
from flask import Flask, send_from_directory
|
| 6 |
-
from threading import Thread
|
| 7 |
from pathlib import Path
|
| 8 |
from moviepy.editor import VideoFileClip
|
| 9 |
import gradio as gr
|
| 10 |
from gradio import components
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
app = Flask(__name__)
|
| 14 |
-
|
| 15 |
output_dir = Path.cwd() / "output"
|
| 16 |
output_dir.mkdir(exist_ok=True)
|
| 17 |
|
| 18 |
-
@app.route('/files/<path:path>')
|
| 19 |
-
def serve_file(path):
|
| 20 |
-
return send_from_directory(output_dir, path)
|
| 21 |
-
|
| 22 |
-
# Start the Flask server in a new thread
|
| 23 |
-
Thread(target=app.run, kwargs={'host': '0.0.0.0', 'port': 5000}).start()
|
| 24 |
-
|
| 25 |
logging.basicConfig(level=logging.INFO)
|
| 26 |
|
| 27 |
def download_file(url, destination):
|
|
@@ -92,6 +81,13 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
|
|
| 92 |
master_playlist_path = create_master_playlist(output_paths)
|
| 93 |
output_paths.append(master_playlist_path)
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
html_blocks = []
|
| 96 |
|
| 97 |
for path in output_paths:
|
|
@@ -120,10 +116,10 @@ video_url = components.Textbox(placeholder="or paste video url here", label="Vid
|
|
| 120 |
interface = gr.Interface(
|
| 121 |
fn=convert_video,
|
| 122 |
inputs=[video_file, quality, aspect_ratio, video_url],
|
| 123 |
-
outputs=
|
| 124 |
title="Video Converter",
|
| 125 |
description="A simple video converter app",
|
| 126 |
-
allow_flagging=
|
| 127 |
)
|
| 128 |
|
| 129 |
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 2 |
import requests
|
| 3 |
from urllib.parse import urlparse
|
| 4 |
import subprocess
|
|
|
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from moviepy.editor import VideoFileClip
|
| 7 |
import gradio as gr
|
| 8 |
from gradio import components
|
| 9 |
|
| 10 |
+
# Define output directory
|
|
|
|
|
|
|
| 11 |
output_dir = Path.cwd() / "output"
|
| 12 |
output_dir.mkdir(exist_ok=True)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
|
| 16 |
def download_file(url, destination):
|
|
|
|
| 81 |
master_playlist_path = create_master_playlist(output_paths)
|
| 82 |
output_paths.append(master_playlist_path)
|
| 83 |
|
| 84 |
+
# After generating the video files, return paths to them
|
| 85 |
+
output_files = [str(path) for path in output_paths]
|
| 86 |
+
|
| 87 |
+
return output_files
|
| 88 |
+
|
| 89 |
+
# Change "video" to "file"
|
| 90 |
+
video_file = gr.inputs.File(label="Your video file") # Remove `type="video"`
|
| 91 |
html_blocks = []
|
| 92 |
|
| 93 |
for path in output_paths:
|
|
|
|
| 116 |
interface = gr.Interface(
|
| 117 |
fn=convert_video,
|
| 118 |
inputs=[video_file, quality, aspect_ratio, video_url],
|
| 119 |
+
outputs=gr.outputs.Video(label="Download Links"), # Changed to gr.outputs.Video
|
| 120 |
title="Video Converter",
|
| 121 |
description="A simple video converter app",
|
| 122 |
+
allow_flagging=False # Updated to False
|
| 123 |
)
|
| 124 |
|
| 125 |
interface.launch(server_name="0.0.0.0", server_port=7860)
|