huu-ontocord commited on
Commit
085bc84
·
verified ·
1 Parent(s): 931cdaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -8
app.py CHANGED
@@ -9,6 +9,37 @@ api = HfApi()
9
  # Replace with your Hugging Face username and repository name
10
  REPO_ID = "ontocord/prompt-share-storage"
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def save_to_json(text1, text2, text3, video, agree):
13
  """Saves the input text and video with UUIDs to files and uploads to Hugging Face Hub."""
14
  if agree:
@@ -20,9 +51,7 @@ def save_to_json(text1, text2, text3, video, agree):
20
  video.save(video_filename)
21
 
22
  data = {
23
- "text1": text1,
24
- "text2": text2,
25
- "text3": text3,
26
  "video_filename": video_filename
27
  }
28
 
@@ -47,18 +76,30 @@ def save_to_json(text1, text2, text3, video, agree):
47
  else:
48
  return "Please agree to the terms before submitting."
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  iface = gr.Interface(
51
  fn=save_to_json,
52
  inputs=[
53
- 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."),
54
- 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)"),
55
- 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)"),
56
  gr.Video(format="mp4"),
 
57
  gr.Checkbox(label="I agree and have the rights to share these prompts under the CC-BY license.")
58
  ],
59
  outputs="text",
60
  title="Save Text and Video to Hugging Face",
61
- 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."
62
  )
63
-
64
  iface.launch()
 
9
  # Replace with your Hugging Face username and repository name
10
  REPO_ID = "ontocord/prompt-share-storage"
11
 
12
+ import gradio as gr
13
+ import cv2
14
+
15
+ def process_video(input_video):
16
+ cap = cv2.VideoCapture(input_video)
17
+
18
+ output_path = "output.mp4"
19
+
20
+ fps = int(cap.get(cv2.CAP_PROP_FPS))
21
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
22
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
23
+
24
+ video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
25
+
26
+ iterating, frame = cap.read()
27
+ while iterating:
28
+
29
+ # flip frame vertically
30
+ frame = cv2.flip(frame, 0)
31
+ display_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
32
+
33
+ video.write(frame)
34
+ yield display_frame, None
35
+
36
+ iterating, frame = cap.read()
37
+
38
+ video.release()
39
+ yield display_frame, output_path
40
+
41
+
42
+
43
  def save_to_json(text1, text2, text3, video, agree):
44
  """Saves the input text and video with UUIDs to files and uploads to Hugging Face Hub."""
45
  if agree:
 
51
  video.save(video_filename)
52
 
53
  data = {
54
+ "text": text1,
 
 
55
  "video_filename": video_filename
56
  }
57
 
 
76
  else:
77
  return "Please agree to the terms before submitting."
78
 
79
+
80
+ with gr.Blocks() as demo:
81
+ with gr.Row():
82
+ input_video = gr.Video(label="input")
83
+ processed_frames = gr.Image(label="last frame")
84
+ output_video = gr.Video(label="output")
85
+
86
+ with gr.Row():
87
+ process_video_btn = gr.Button("process video")
88
+
89
+ process_video_btn.click(process_video, input_video, [processed_frames, output_video])
90
+
91
+
92
+ """
93
  iface = gr.Interface(
94
  fn=save_to_json,
95
  inputs=[
 
 
 
96
  gr.Video(format="mp4"),
97
+ 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)"),
98
  gr.Checkbox(label="I agree and have the rights to share these prompts under the CC-BY license.")
99
  ],
100
  outputs="text",
101
  title="Save Text and Video to Hugging Face",
102
+ 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!"
103
  )
104
+ """
105
  iface.launch()