jschwab21 commited on
Commit
470c06d
·
verified ·
1 Parent(s): 17c0909

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -150
app.py CHANGED
@@ -1,161 +1,24 @@
1
- import os
2
  import gradio as gr
3
- from video_processing import process_video
4
- from gradio.themes.base import Base
5
- from gradio.themes.utils import colors, fonts, sizes
6
- from typing import Iterable
7
 
8
-
9
- class CustomTheme(Base):
10
- def __init__(
11
- self,
12
- *,
13
- primary_hue: colors.Color | str = colors.orange,
14
- secondary_hue: colors.Color | str = colors.orange,
15
- neutral_hue: colors.Color | str = colors.gray,
16
- spacing_size: sizes.Size | str = sizes.spacing_md,
17
- radius_size: sizes.Size | str = sizes.radius_md,
18
- text_size: sizes.Size | str = sizes.text_md,
19
- font: fonts.Font | str | Iterable[fonts.Font | str] = (
20
- fonts.GoogleFont("Sora"),
21
- "ui-sans-serif",
22
- "sans-serif",
23
- ),
24
- font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
25
- fonts.GoogleFont("Sora"),
26
- "ui-monospace",
27
- "monospace",
28
- ),
29
- ):
30
- super().__init__(
31
- primary_hue=primary_hue,
32
- secondary_hue=secondary_hue,
33
- neutral_hue=neutral_hue,
34
- spacing_size=spacing_size,
35
- radius_size=radius_size,
36
- text_size=text_size,
37
- font=font,
38
- font_mono=font_mono,
39
- )
40
- super().set(
41
- body_background_fill="radial-gradient(circle at center, rgba(235, 87, 38, 1) 0%, rgba(235, 87, 38, 0) 70%), radial-gradient(#eb5726 1px, transparent 1px)",
42
- body_text_color="#282828",
43
- block_background_fill="#ffffff",
44
- block_title_text_color="#eb5726",
45
- block_label_text_color="#eb5726",
46
- button_primary_background_fill="#eb5726",
47
- button_primary_text_color="#ffffff",
48
- )
49
-
50
- custom_theme = CustomTheme()
51
-
52
- from datetime import datetime
53
-
54
- def save_uploaded_file(uploaded_bytes):
55
- upload_dir = "uploaded_videos"
56
- os.makedirs(upload_dir, exist_ok=True)
57
- # Generate a unique filename using timestamp to avoid overwriting files
58
- file_name = f"uploaded_video_{datetime.now().strftime('%Y%m%d%H%M%S')}.mp4"
59
- file_path = os.path.join(upload_dir, file_name)
60
- with open(file_path, "wb") as f:
61
- f.write(uploaded_bytes)
62
- return file_path
63
-
64
- def display_results(video_file):
65
- if video_file:
66
- video_file_path = save_uploaded_file(video_file) # Assume this function returns the saved file path
67
- scenes = find_scenes(video_file_path)
68
- if scenes:
69
- return f"Detected scenes: {scenes}"
70
- else:
71
- return "No scenes detected."
72
- else:
73
- return "No file uploaded."
74
-
75
-
76
- css = """
77
- body {
78
- background-color: #ffffff;
79
- background-image: radial-gradient(#eb5726 1px, transparent 1px);
80
- background-size: 10px 10px;
81
- background-repeat: repeat;
82
- background-attachment: fixed;
83
- }
84
- #video_url {
85
- background-color: #ffffff;
86
- color: #282828;
87
- border: 2px solid #eb5726;
88
- }
89
- #description {
90
- background-color: #ffffff;
91
- color: #282828;
92
- border: 2px solid #eb5726;
93
- }
94
- #submit_button {
95
- background-color: #eb5726;
96
- color: #ffffff;
97
- border: 2px solid #ffffff;
98
- }
99
- #submit_button:hover {
100
- background-color: #f5986e;
101
- color: #ffffff;
102
- border: 2px solid #ffffff;
103
- }
104
- label[for="video_url"] {
105
- color: #eb5726 !important;
106
- }
107
- label[for="description"] {
108
- color: #eb5726 !important;
109
- }
110
- h3 {
111
- color: #eb5726;
112
- }
113
- .centered-markdown {
114
- text-align: center;
115
- background-color: #ffffff;
116
- padding: 10px;
117
- }
118
- #sickstadium-title {
119
- font-size: 3em !important;
120
- font-weight: bold;
121
- text-transform: uppercase;
122
- }
123
- """
124
-
125
- def interface_function(video_file):
126
- if video_file is not None:
127
- file_path = save_uploaded_file(video_file)
128
- return f"File saved at {file_path}"
129
- return "No file uploaded."
130
-
131
- def test_upload(uploaded_file):
132
- if uploaded_file is None:
133
- return "No file uploaded."
134
  try:
135
- # Save the uploaded file and process it
136
- file_path = save_uploaded_file(uploaded_file)
137
- if not file_path:
138
- return "Failed to save file."
139
-
140
- # Process the video using the path
141
- result_path = process_video(file_path, description="Describe your clip here", is_url=False)
142
- if not result_path:
143
- return "Failed to process video or no scenes found."
144
-
145
- return f"Video processed and saved to: {result_path}"
146
  except Exception as e:
147
- # Catch any exceptions that occur and return them for debugging
148
- return f"An error occurred: {str(e)}"
149
 
150
  with gr.Blocks() as demo:
151
  with gr.Column():
152
  video_file = gr.UploadButton("Upload Video File", type="binary", file_types=["video"])
153
- output = gr.Textbox(label="Output")
154
- submit_button = gr.Button("Process Video")
 
155
  submit_button.click(
156
- fn=test_upload,
157
- inputs=[video_file],
158
- outputs=[output]
159
  )
160
 
161
- demo.launch()
 
 
1
  import gradio as gr
 
 
 
 
2
 
3
+ def display_video(video_file):
4
+ if video_file is None:
5
+ return None, "No video uploaded."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  try:
7
+ # Directly return the path to the uploaded video file for displaying
8
+ return video_file, None
 
 
 
 
 
 
 
 
 
9
  except Exception as e:
10
+ return None, f"An error occurred: {str(e)}"
 
11
 
12
  with gr.Blocks() as demo:
13
  with gr.Column():
14
  video_file = gr.UploadButton("Upload Video File", type="binary", file_types=["video"])
15
+ output_video = gr.Video()
16
+ output_message = gr.Textbox(label="Output Message")
17
+ submit_button = gr.Button("Display Video")
18
  submit_button.click(
19
+ fn=display_video,
20
+ inputs=video_file,
21
+ outputs=[output_video, output_message]
22
  )
23
 
24
+ demo.launch()