Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import tempfile
|
| 3 |
-
from pathlib import Path
|
| 4 |
import requests
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
client = LitterboxClient()
|
| 30 |
-
|
| 31 |
-
def gradio_upload(video_file):
|
| 32 |
-
if not video_file:
|
| 33 |
-
return "No file provided"
|
| 34 |
-
|
| 35 |
-
path = Path(video_file.name)
|
| 36 |
-
# Save the uploaded file temporarily
|
| 37 |
-
temp_path = tempfile.mktemp(suffix=path.suffix)
|
| 38 |
-
with open(temp_path, "wb") as f:
|
| 39 |
-
f.write(video_file.read())
|
| 40 |
-
|
| 41 |
-
# Upload using your exact class
|
| 42 |
-
return client.upload_file(temp_path)
|
| 43 |
-
|
| 44 |
-
with gr.Blocks() as demo:
|
| 45 |
-
gr.Markdown("## Test Litterbox Upload (Pure Script)")
|
| 46 |
-
video_input = gr.File(label="Upload Video")
|
| 47 |
-
output = gr.Textbox(label="Uploaded URL / Error")
|
| 48 |
-
run_btn = gr.Button("Upload")
|
| 49 |
-
run_btn.click(gradio_upload, inputs=video_input, outputs=output)
|
| 50 |
-
|
| 51 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import requests
|
| 3 |
+
import tempfile
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def get_gofile_server():
|
| 7 |
+
r = requests.get("https://api.gofile.io/servers")
|
| 8 |
+
r.raise_for_status()
|
| 9 |
+
return r.json()["data"]["servers"][0]["name"]
|
| 10 |
+
|
| 11 |
+
def upload_test(file):
|
| 12 |
+
if not file:
|
| 13 |
+
return "No file"
|
| 14 |
+
server = get_gofile_server()
|
| 15 |
+
url = f"https://{server}.gofile.io/uploadFile"
|
| 16 |
+
filename = os.path.basename(file.name)
|
| 17 |
+
with open(file.name, "rb") as f:
|
| 18 |
+
r = requests.post(url, files={"file": (filename, f)})
|
| 19 |
+
r.raise_for_status()
|
| 20 |
+
data = r.json()
|
| 21 |
+
if data["status"] == "ok":
|
| 22 |
+
return f"Success!\nDirect link: {data['data']['directLink']}"
|
| 23 |
+
return f"Error: {data}"
|
| 24 |
+
|
| 25 |
+
gr.Interface(upload_test, gr.File(), gr.Textbox()).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|