vericudebuget commited on
Commit
436734f
·
verified ·
1 Parent(s): 2e0eb40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -53
app.py CHANGED
@@ -1,63 +1,34 @@
1
  import gradio as gr
2
- from datetime import datetime
3
- import random
4
- import uuid
5
- from dataclasses import dataclass
6
 
7
- # Shared state to store messages
8
- messages = []
9
 
10
- # Dictionary to store user colors
11
- user_colors = {}
12
-
13
- @dataclass
14
- class Data:
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
- # Add the new message to the shared state
31
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
32
- user_color = get_user_color(user_id)
33
- messages.append(Data(user_id=user_id, message=message, timestamp=timestamp))
 
 
 
34
 
35
- # Update the chat history
36
- history.append(f"User_{user_id[:4]}: {message} ({timestamp})")
37
- return "", history
38
 
39
- def get_updates(history):
40
- global messages
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
- chatbot = gr.Chatbot()
52
- msg = gr.Textbox(label="Type your message here (format: 'id here; text here')")
53
- clear = gr.Button("Clear")
54
-
55
- msg.submit(chat, [msg, chatbot], [msg, chatbot])
56
- clear.click(lambda: [], outputs=[chatbot])
57
 
58
- # Add an update function that runs every 0.2 seconds
59
- demo.load(get_updates, inputs=chatbot, outputs=chatbot, every=0.2)
60
 
61
- # Launch the app
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()