Neon-AI commited on
Commit
6bf8e04
·
verified ·
1 Parent(s): ee283b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -5,19 +5,24 @@ def upload_to_litterbox(video_file):
5
  """
6
  Uploads a video file to Litterbox and returns the direct URL.
7
  """
8
- files = {
9
- 'fileToUpload': (video_file.name, open(video_file.name, 'rb'), 'video/mp4')
10
- }
11
- data = {
12
- 'reqtype': 'fileupload'
13
- }
14
-
15
- resp = requests.post("https://litter.catbox.moe/resources/internals/api.php", files=files, data=data)
16
-
17
- if resp.status_code == 200:
18
- return resp.text # This is the direct .mp4 link
19
- else:
20
- return f"Upload failed with status {resp.status_code}"
 
 
 
 
 
21
 
22
  with gr.Blocks() as demo:
23
  gr.Markdown("## Upload Video to Litterbox / Catbox")
 
5
  """
6
  Uploads a video file to Litterbox and returns the direct URL.
7
  """
8
+ try:
9
+ with open(video_file.name, "rb") as f:
10
+ files = {"fileToUpload": (video_file.name, f, "video/mp4")}
11
+ data = {"reqtype": "fileupload"}
12
+
13
+ resp = requests.post(
14
+ "https://litter.catbox.moe/resources/internals/api.php",
15
+ files=files,
16
+ data=data
17
+ )
18
+
19
+ if resp.status_code == 200 and resp.text.startswith("https://"):
20
+ return resp.text
21
+ else:
22
+ return f"Upload failed: {resp.status_code} - {resp.text}"
23
+
24
+ except Exception as e:
25
+ return f"Error: {e}"
26
 
27
  with gr.Blocks() as demo:
28
  gr.Markdown("## Upload Video to Litterbox / Catbox")