Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def save_to_json(text1, text2, text3, video, agree):
|
5 |
-
"""Saves the input text and video to
|
6 |
if agree:
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
9 |
video.save(video_filename)
|
10 |
|
11 |
data = {
|
@@ -14,24 +25,40 @@ def save_to_json(text1, text2, text3, video, agree):
|
|
14 |
"text3": text3,
|
15 |
"video_filename": video_filename
|
16 |
}
|
17 |
-
|
|
|
|
|
|
|
18 |
json.dump(data, f)
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
else:
|
21 |
return "Please agree to the terms before submitting."
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=save_to_json,
|
25 |
inputs=[
|
26 |
-
gr.TextArea(lines=5, placeholder="Enter
|
27 |
-
gr.TextArea(lines=5, placeholder="Enter
|
28 |
-
gr.TextArea(lines=5, placeholder="Enter
|
29 |
gr.Video(format="mp4"),
|
30 |
gr.Checkbox(label="I agree and have the rights to share these prompts under the CC-BY license.")
|
31 |
],
|
32 |
outputs="text",
|
33 |
-
title="Save Text and Video to
|
34 |
-
description="Enter
|
35 |
)
|
36 |
|
37 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
+
from huggingface_hub import HfApi
|
4 |
+
import uuid
|
5 |
+
|
6 |
+
# Initialize the Hugging Face API
|
7 |
+
api = HfApi()
|
8 |
+
|
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:
|
15 |
+
# Generate a unique UUID
|
16 |
+
file_uuid = str(uuid.uuid4())
|
17 |
+
|
18 |
+
# Save the video with UUID prepended to the filename
|
19 |
+
video_filename = f"{file_uuid}_uploaded_video.mp4"
|
20 |
video.save(video_filename)
|
21 |
|
22 |
data = {
|
|
|
25 |
"text3": text3,
|
26 |
"video_filename": video_filename
|
27 |
}
|
28 |
+
|
29 |
+
# Save the JSON with UUID prepended to the filename
|
30 |
+
json_filename = f"{file_uuid}_data.json"
|
31 |
+
with open(json_filename, "w") as f:
|
32 |
json.dump(data, f)
|
33 |
+
|
34 |
+
# Upload the files to Hugging Face Hub
|
35 |
+
api.upload_file(
|
36 |
+
path_or_fileobj=json_filename,
|
37 |
+
path_in_repo=json_filename,
|
38 |
+
repo_id=REPO_ID
|
39 |
+
)
|
40 |
+
api.upload_file(
|
41 |
+
path_or_fileobj=video_filename,
|
42 |
+
path_in_repo=video_filename,
|
43 |
+
repo_id=REPO_ID
|
44 |
+
)
|
45 |
+
|
46 |
+
return "Data saved and uploaded to Hugging Face Hub."
|
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()
|