Spaces:
Sleeping
Sleeping
import gradio as gr | |
import json | |
from huggingface_hub import HfApi | |
import uuid | |
# Initialize the Hugging Face API | |
api = HfApi() | |
# Replace with your Hugging Face username and repository name | |
REPO_ID = "ontocord/prompt-share-storage" | |
def save_to_json(text1, text2, text3, video, agree): | |
"""Saves the input text and video with UUIDs to files and uploads to Hugging Face Hub.""" | |
if agree: | |
# Generate a unique UUID | |
file_uuid = str(uuid.uuid4()) | |
# Save the video with UUID prepended to the filename | |
video_filename = f"{file_uuid}_uploaded_video.mp4" | |
video.save(video_filename) | |
data = { | |
"text1": text1, | |
"text2": text2, | |
"text3": text3, | |
"video_filename": video_filename | |
} | |
# Save the JSON with UUID prepended to the filename | |
json_filename = f"{file_uuid}_data.json" | |
with open(json_filename, "w") as f: | |
json.dump(data, f) | |
# Upload the files to Hugging Face Hub | |
api.upload_file( | |
path_or_fileobj=json_filename, | |
path_in_repo=json_filename, | |
repo_id=REPO_ID | |
) | |
api.upload_file( | |
path_or_fileobj=video_filename, | |
path_in_repo=video_filename, | |
repo_id=REPO_ID | |
) | |
return "Data saved and uploaded to Hugging Face Hub." | |
else: | |
return "Please agree to the terms before submitting." | |
iface = gr.Interface( | |
fn=save_to_json, | |
inputs=[ | |
gr.TextArea(lines=5, placeholder="Enter a conversation about video (e.g., Q: Hi - what am I doing? A: Good, it looks like you are at a cafe."), | |
gr.TextArea(lines=5, placeholder="Enter a detailed description about the video (e.g., This video shows a person at a cafe, with nosiy happy patrons, and a dynamic atmosphere)"), | |
gr.TextArea(lines=5, placeholder="Enter a question and answer that requires reasoning (e.g., Q: If two friends joined, how many coffees would be needed? A: Since you have one coffee in your hand, and two friends joined you, assuming they each like a coffee, two more coffees are needed, making a total of 3 coffees in this scene)"), | |
gr.Video(format="mp4"), | |
gr.Checkbox(label="I agree and have the rights to share these prompts under the CC-BY license.") | |
], | |
outputs="text", | |
title="Save Text and Video to Hugging Face", | |
description="Share a video and creation AI training data. Enter a conversation, description and reasoning prompts about the video you upload, upload the video, and click submit to save to ontocord/prompt-share-storage Dataset. DO NOT share personal information." | |
) | |
iface.launch() |