Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
-
import uuid
|
| 5 |
-
from dataclasses import dataclass
|
| 6 |
|
| 7 |
-
|
| 8 |
-
messages = []
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
user_id: str
|
| 16 |
-
message: str
|
| 17 |
-
timestamp: str
|
| 18 |
-
|
| 19 |
-
def get_user_color(user_id):
|
| 20 |
-
if user_id not in user_colors:
|
| 21 |
-
user_colors[user_id] = f"#{random.randint(0, 0xFFFFFF):06x}"
|
| 22 |
-
return user_colors[user_id]
|
| 23 |
-
|
| 24 |
-
def chat(input_text, history):
|
| 25 |
-
global messages
|
| 26 |
-
|
| 27 |
-
# Parse the input to get user_id and message
|
| 28 |
-
user_id, message = input_text.split("; ")
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
history.append(f"User_{user_id[:4]}: {message} ({timestamp})")
|
| 37 |
-
return "", history
|
| 38 |
|
| 39 |
-
def
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# Check if there are new messages
|
| 43 |
-
if len(messages) > len(history):
|
| 44 |
-
return [f"User_{msg.user_id[:4]}: {msg.message} ({msg.timestamp})" for msg in messages]
|
| 45 |
-
|
| 46 |
-
# If no new messages, return the current history
|
| 47 |
-
return history
|
| 48 |
|
| 49 |
-
# Create the Gradio interface
|
| 50 |
with gr.Blocks() as demo:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
msg.submit(chat, [msg, chatbot], [msg, chatbot])
|
| 56 |
-
clear.click(lambda: [], outputs=[chatbot])
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
if __name__ == "__main__":
|
| 63 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
api = HfApi()
|
|
|
|
| 6 |
|
| 7 |
+
def upload_video(video):
|
| 8 |
+
# Save the uploaded video to a temporary file
|
| 9 |
+
video_path = os.path.join("temp", video.name)
|
| 10 |
+
with open(video_path, "wb") as f:
|
| 11 |
+
f.write(video.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Upload the video to Hugging Face
|
| 14 |
+
api.upload_file(
|
| 15 |
+
path_or_fileobj=video_path,
|
| 16 |
+
path_in_repo=f"/videos/{video.name}",
|
| 17 |
+
repo_id="vericudebuget/ok4231",
|
| 18 |
+
repo_type="space",
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
return f"Uploaded {video.name} successfully!"
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
def progress_bar(video):
|
| 24 |
+
return f"Uploading {video.name}..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
| 26 |
with gr.Blocks() as demo:
|
| 27 |
+
video_input = gr.File(label="Upload Video")
|
| 28 |
+
progress = gr.Textbox(label="Progress")
|
| 29 |
+
output = gr.Textbox(label="Output")
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
video_input.change(progress_bar, inputs=video_input, outputs=progress)
|
| 32 |
+
video_input.upload(upload_video, inputs=video_input, outputs=output)
|
| 33 |
|
| 34 |
+
demo.launch()
|
|
|
|
|
|