Spaces:
Build error
Build error
Commit
·
2f46c24
1
Parent(s):
b2bbc7c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from requests_toolbelt import MultipartEncoder
|
4 |
+
|
5 |
+
def put_video(video_url, page_id, access_token, description, title):
|
6 |
+
video_file_name = title
|
7 |
+
local_video_file = video_url
|
8 |
+
path = f"{page_id}/videos"
|
9 |
+
fb_url = f"https://graph-video.facebook.com/{path}?access_token={access_token}"
|
10 |
+
print(fb_url)
|
11 |
+
m = MultipartEncoder(
|
12 |
+
fields={
|
13 |
+
"description": description,
|
14 |
+
"title": title,
|
15 |
+
"comment": "postvideo",
|
16 |
+
"file_url": video_url,
|
17 |
+
}
|
18 |
+
)
|
19 |
+
r = requests.post(
|
20 |
+
fb_url, headers={"Content-Type": m.content_type}, data=m
|
21 |
+
)
|
22 |
+
if r.status_code == 200:
|
23 |
+
j_res = r.json()
|
24 |
+
facebook_video_id = j_res.get("id")
|
25 |
+
print("facebook_video_id = {0}".format(facebook_video_id))
|
26 |
+
print("uploaddone, after 1,2 min will show ur profile")
|
27 |
+
else:
|
28 |
+
print("Facebook upload error: {0}".format(r.text))
|
29 |
+
print(video_url)
|
30 |
+
|
31 |
+
def facebook_video_uploader(video_url, page_id, access_token, description, title):
|
32 |
+
put_video(video_url, page_id, access_token, description, title)
|
33 |
+
return "Video upload completed!"
|
34 |
+
|
35 |
+
inputs = [
|
36 |
+
gr.inputs.Textbox("Video URL"),
|
37 |
+
gr.inputs.Textbox("Page ID"),
|
38 |
+
gr.inputs.Textbox("Access Token"),
|
39 |
+
gr.inputs.Textbox("Description"),
|
40 |
+
gr.inputs.Textbox("Title"),
|
41 |
+
]
|
42 |
+
output = gr.outputs.Textbox()
|
43 |
+
|
44 |
+
gr.Interface(
|
45 |
+
fn=facebook_video_uploader,
|
46 |
+
inputs=inputs,
|
47 |
+
outputs=output,
|
48 |
+
title="Facebook Video Uploader",
|
49 |
+
description="Upload your videos to Facebook with this uploader.",
|
50 |
+
theme="light",
|
51 |
+
).launch()
|