File size: 2,592 Bytes
a4b1eaf
 
931cdaf
 
 
 
 
 
 
 
a4b1eaf
6b40782
931cdaf
a4b1eaf
931cdaf
 
 
 
 
9f2ebbe
6b40782
a4b1eaf
 
 
6b40782
 
a4b1eaf
931cdaf
 
 
 
a4b1eaf
931cdaf
 
 
 
 
 
 
 
 
 
 
 
 
 
a4b1eaf
 
 
 
 
 
931cdaf
 
 
9f2ebbe
 
a4b1eaf
 
931cdaf
 
a4b1eaf
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
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()