Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
-
with open(
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
r.raise_for_status()
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
if data.get("success"):
|
| 13 |
-
return data["link"]
|
| 14 |
-
return "Failed (non-JSON/HTML response)"
|
| 15 |
except Exception as e:
|
| 16 |
-
return f"Failed: {e}"
|
| 17 |
|
| 18 |
-
gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import tempfile
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
LITTERBOX_API = "https://litterbox.catbox.moe/resources/internals/api.php"
|
| 7 |
+
|
| 8 |
+
def upload_litterbox(file):
|
| 9 |
+
if not file:
|
| 10 |
+
return "No file uploaded"
|
| 11 |
+
filename = os.path.basename(file.name)
|
| 12 |
try:
|
| 13 |
+
with open(file.name, "rb") as f:
|
| 14 |
+
files = {"fileToUpload": (filename, f)}
|
| 15 |
+
data = {"reqtype": "fileupload", "time": "72h"}
|
| 16 |
+
r = requests.post(LITTERBOX_API, data=data, files=files, timeout=300)
|
| 17 |
r.raise_for_status()
|
| 18 |
+
url = r.text.strip()
|
| 19 |
+
return f"Success!\nRaw MP4 link: {url}"
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
+
return f"Failed: {str(e)}"
|
| 22 |
|
| 23 |
+
gr.Interface(
|
| 24 |
+
fn=upload_litterbox,
|
| 25 |
+
inputs=gr.File(label="Upload Video"),
|
| 26 |
+
outputs=gr.Textbox(label="Result"),
|
| 27 |
+
title="Litterbox Upload Test",
|
| 28 |
+
description="Upload MP4 → get raw link (up to 1GB, 72h expiry)"
|
| 29 |
+
).launch()
|