File size: 3,797 Bytes
a4b1eaf
 
931cdaf
 
 
 
 
 
 
 
a4b1eaf
085bc84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b40782
931cdaf
a4b1eaf
931cdaf
 
 
 
 
9f2ebbe
6b40782
a4b1eaf
085bc84
6b40782
a4b1eaf
931cdaf
 
 
 
a4b1eaf
931cdaf
 
 
 
 
 
 
 
 
 
 
 
 
 
a4b1eaf
 
 
085bc84
 
 
 
 
 
 
 
 
 
 
 
 
 
a4b1eaf
 
 
9f2ebbe
085bc84
9f2ebbe
a4b1eaf
 
931cdaf
085bc84
a4b1eaf
085bc84
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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" 

import gradio as gr
import cv2

def process_video(input_video):
    cap = cv2.VideoCapture(input_video)

    output_path = "output.mp4"

    fps = int(cap.get(cv2.CAP_PROP_FPS))
    width  = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

    video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))

    iterating, frame = cap.read()
    while iterating:

        # flip frame vertically
        frame = cv2.flip(frame, 0)
        display_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        video.write(frame)
        yield display_frame, None

        iterating, frame = cap.read()

    video.release()
    yield display_frame, output_path



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 = {
          "text": text1,
          "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."


with gr.Blocks() as demo:
    with gr.Row():
        input_video = gr.Video(label="input")
        processed_frames = gr.Image(label="last frame")
        output_video = gr.Video(label="output")

    with gr.Row():
        process_video_btn = gr.Button("process video")

    process_video_btn.click(process_video, input_video, [processed_frames, output_video])


"""
iface = gr.Interface(
  fn=save_to_json,
  inputs=[
      gr.Video(format="mp4"), 
      gr.TextArea(lines=5, placeholder="(Optional) Enter something that would help an AI understand this video, like a pretend conversation about the video (e.g., Q: Hi - what am I doing? A: Good, it looks like you are at a cafe.)\n-Or a detailed description about the video (e.g., This video shows a person at a cafe, with nosiy happy patrons, and a dynamic atmosphere)\n - or 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.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 help create an open source AI training dataset. Just take a video and describe what you see, what you are doing, or have a conversation with someone. Make sure everyone has consented to be in the video. Optionally enter in some text that might help an AI understand the vidoe. Then click submit to save to ontocord/prompt-share-storage Dataset. DO NOT share personal information. Thank you!"
)
"""
iface.launch()