Spaces:
Build error
Build error
File size: 1,597 Bytes
2f46c24 |
1 2 3 4 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import gradio as gr
import requests
from requests_toolbelt import MultipartEncoder
def put_video(video_url, page_id, access_token, description, title):
video_file_name = title
local_video_file = video_url
path = f"{page_id}/videos"
fb_url = f"https://graph-video.facebook.com/{path}?access_token={access_token}"
print(fb_url)
m = MultipartEncoder(
fields={
"description": description,
"title": title,
"comment": "postvideo",
"file_url": video_url,
}
)
r = requests.post(
fb_url, headers={"Content-Type": m.content_type}, data=m
)
if r.status_code == 200:
j_res = r.json()
facebook_video_id = j_res.get("id")
print("facebook_video_id = {0}".format(facebook_video_id))
print("uploaddone, after 1,2 min will show ur profile")
else:
print("Facebook upload error: {0}".format(r.text))
print(video_url)
def facebook_video_uploader(video_url, page_id, access_token, description, title):
put_video(video_url, page_id, access_token, description, title)
return "Video upload completed!"
inputs = [
gr.inputs.Textbox("Video URL"),
gr.inputs.Textbox("Page ID"),
gr.inputs.Textbox("Access Token"),
gr.inputs.Textbox("Description"),
gr.inputs.Textbox("Title"),
]
output = gr.outputs.Textbox()
gr.Interface(
fn=facebook_video_uploader,
inputs=inputs,
outputs=output,
title="Facebook Video Uploader",
description="Upload your videos to Facebook with this uploader.",
theme="light",
).launch()
|