Neon-AI commited on
Commit
ff47e01
·
verified ·
1 Parent(s): ad4587e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -22
app.py CHANGED
@@ -1,30 +1,50 @@
1
  import gradio as gr
2
  import requests
3
- import tempfile
4
- import os
 
5
 
6
- UPLOAD_URL = "https://0x0.st"
 
7
 
8
- def upload_test(file):
9
- if file is None:
10
- return "No file uploaded"
11
-
12
- filename = os.path.basename(file.name)
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  try:
14
- with open(file.name, "rb") as f:
15
- r = requests.post(UPLOAD_URL, files={"file": (filename, f)}, timeout=180)
16
  r.raise_for_status()
17
- url = r.text.strip()
18
- return f"Uploaded successfully!\n\nFile: {filename}\nURL: {url}"
 
 
 
 
 
19
  except Exception as e:
20
- return f"Upload failed: {str(e)}"
21
-
22
- iface = gr.Interface(
23
- fn=upload_test,
24
- inputs=gr.File(label="Upload a video file (any size, up to ~512MB)"),
25
- outputs=gr.Textbox(label="Result"),
26
- title="0x0.st Upload Test",
27
- description="Test uploading to 0x0.st directly. Use a small video first."
28
- )
29
 
30
- iface.launch()
 
 
1
  import gradio as gr
2
  import requests
3
+ import re
4
+ from fastapi import FastAPI
5
+ from fastapi.middleware.cors import CORSMiddleware
6
 
7
+ # Gradio + FastAPI backend
8
+ app = FastAPI(title="Catbox Raw File Extractor API")
9
 
10
+ # Allow all origins (for frontend)
11
+ app.add_middleware(
12
+ CORSMiddleware,
13
+ allow_origins=["*"],
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
+ )
17
+
18
+ def get_direct_link(catbox_url: str):
19
+ """Extract direct raw file from a Catbox/Litterbox URL"""
20
+ if not catbox_url.startswith("http"):
21
+ return {"ok": False, "error": "Invalid URL"}
22
+
23
+ # If it already ends with a raw file extension, return as-is
24
+ if re.search(r'\.(mp4|png|jpg|jpeg|gif|webm)$', catbox_url, re.IGNORECASE):
25
+ return {"ok": True, "direct_link": catbox_url}
26
+
27
+ # Otherwise, try to fetch page and extract
28
  try:
29
+ r = requests.get(catbox_url, timeout=10)
 
30
  r.raise_for_status()
31
+ text = r.text
32
+
33
+ match = re.search(r'src="([^"]+\.(mp4|png|jpg|jpeg|gif|webm))"', text, re.IGNORECASE)
34
+ if match:
35
+ return {"ok": True, "direct_link": match.group(1)}
36
+ else:
37
+ return {"ok": False, "error": "Could not find raw file link"}
38
  except Exception as e:
39
+ return {"ok": False, "error": str(e)}
40
+
41
+ # Gradio API interface
42
+ with gr.Blocks(server_name="0.0.0.0") as demo:
43
+ gr.Markdown("## Catbox / Litterbox Raw File Extractor API")
44
+ input_url = gr.Textbox(label="Paste Catbox/Litterbox URL")
45
+ output_json = gr.JSON(label="API Response")
46
+ extract_btn = gr.Button("Get Direct Link")
47
+ extract_btn.click(fn=get_direct_link, inputs=input_url, outputs=output_json)
48
 
49
+ # Mount Gradio app onto FastAPI
50
+ app = gr.mount_gradio_app(app, demo, path="/api")