jschwab21 commited on
Commit
4793b98
·
verified ·
1 Parent(s): 76008f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -65
app.py CHANGED
@@ -4,7 +4,6 @@ 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
- import os
8
 
9
  class CustomTheme(Base):
10
  def __init__(
@@ -50,26 +49,28 @@ class CustomTheme(Base):
50
  custom_theme = CustomTheme()
51
 
52
  def save_uploaded_file(uploaded_file):
 
53
  if uploaded_file is None:
54
  return None # Handle cases where no file was uploaded
55
 
 
 
 
 
56
  upload_dir = "uploaded_videos"
57
  os.makedirs(upload_dir, exist_ok=True)
58
  file_path = os.path.join(upload_dir, uploaded_file.name)
59
 
60
  # Save the temporary file to a new location
61
  with open(file_path, "wb") as f:
62
- f.write(uploaded_file.file.read()) # Write file content to disk
63
  f.flush()
64
  os.fsync(f.fileno()) # Ensure all file data is flushed to disk
65
 
66
- print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes") # Debugging
67
  return file_path
68
 
69
-
70
-
71
  def display_results(video_url, video_file, description):
72
- """Process video from URL or file upload and return the results."""
73
  final_clip_path = None
74
 
75
  if video_url:
@@ -86,68 +87,17 @@ def display_results(video_url, video_file, description):
86
  else:
87
  return "No matching scene found", None
88
 
89
- # Custom CSS for additional styling
90
- css = """
91
- body {
92
- background-color: #ffffff;
93
- background-image: radial-gradient(#eb5726 1px, transparent 1px);
94
- background-size: 10px 10px;
95
- background-repeat: repeat;
96
- background-attachment: fixed;
97
- }
98
- #video_url {
99
- background-color: #ffffff;
100
- color: #282828;
101
- border: 2px solid #eb5726;
102
- }
103
- #description {
104
- background-color: #ffffff;
105
- color: #282828;
106
- border: 2px solid #eb5726;
107
- }
108
- #submit_button {
109
- background-color: #eb5726;
110
- color: #ffffff;
111
- border: 2px solid #ffffff;
112
- }
113
- #submit_button:hover {
114
- background-color: #f5986e;
115
- color: #ffffff;
116
- border: 2px solid #ffffff;
117
- }
118
- label[for="video_url"] {
119
- color: #eb5726 !important;
120
- }
121
- label[for="description"] {
122
- color: #eb5726 !important;
123
- }
124
- h3 {
125
- color: #eb5726;
126
- }
127
- .centered-markdown {
128
- text-align: center;
129
- background-color: #ffffff;
130
- padding: 10px;
131
- }
132
- #sickstadium-title {
133
- font-size: 3em !important;
134
- font-weight: bold;
135
- text-transform: uppercase;
136
- }
137
- """
138
-
139
- with gr.Blocks() as demo:
140
  with gr.Column():
141
- video_url = gr.Textbox(label="Video URL")
142
- video_file = gr.File(label="Upload Video File")
143
- description = gr.Textbox(label="Describe your clip")
 
 
 
144
  submit_button = gr.Button("Process Video")
145
  video_output = gr.Video(label="Processed Video")
146
  download_output = gr.File(label="Download Processed Video")
147
- submit_button.click(
148
- fn=display_results,
149
- inputs=[video_url, video_file, description],
150
- outputs=[video_output, download_output]
151
- )
152
 
153
  demo.launch()
 
4
  from gradio.themes.base import Base
5
  from gradio.themes.utils import colors, fonts, sizes
6
  from typing import Iterable
 
7
 
8
  class CustomTheme(Base):
9
  def __init__(
 
49
  custom_theme = CustomTheme()
50
 
51
  def save_uploaded_file(uploaded_file):
52
+ print(f"Received object type: {type(uploaded_file)}")
53
  if uploaded_file is None:
54
  return None # Handle cases where no file was uploaded
55
 
56
+ if isinstance(uploaded_file, gr.NamedString):
57
+ print(f"File path from NamedString: {uploaded_file}")
58
+ return uploaded_file # Directly return the path if it's a NamedString
59
+
60
  upload_dir = "uploaded_videos"
61
  os.makedirs(upload_dir, exist_ok=True)
62
  file_path = os.path.join(upload_dir, uploaded_file.name)
63
 
64
  # Save the temporary file to a new location
65
  with open(file_path, "wb") as f:
66
+ f.write(uploaded_file.read()) # Assuming file is a file-like object
67
  f.flush()
68
  os.fsync(f.fileno()) # Ensure all file data is flushed to disk
69
 
70
+ print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes")
71
  return file_path
72
 
 
 
73
  def display_results(video_url, video_file, description):
 
74
  final_clip_path = None
75
 
76
  if video_url:
 
87
  else:
88
  return "No matching scene found", None
89
 
90
+ with gr.Blocks(theme=custom_theme, css=css) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  with gr.Column():
92
+ gr.Markdown("# **Sickstadium AI**", elem_classes="centered-markdown", elem_id="sickstadium-title")
93
+ gr.Markdown("### Upload your videos. Find sick clips. Tell your truth.", elem_classes="centered-markdown")
94
+ gr.Markdown("**Welcome to Sickstadium AI. Our goal is to empower content creators with the ability to tell their stories without the friction of traditional video editing software. Skip the timeline, and don't worry about your video editing skills. Upload your video, describe the clip you want, and let our AI video editor do the work for you. Get more info about the Sickstadium project at [Strongholdlabs.io](https://strongholdlabs.io/)**", elem_classes="centered-markdown")
95
+ video_url = gr.Textbox(label="Video URL:")
96
+ video_file = gr.File(label="Upload Video File:")
97
+ description = gr.Textbox(label="Describe your clip:")
98
  submit_button = gr.Button("Process Video")
99
  video_output = gr.Video(label="Processed Video")
100
  download_output = gr.File(label="Download Processed Video")
101
+ submit_button.click(fn=display_results, inputs=[video_url, video_file, description], outputs=[video_output, download_output])
 
 
 
 
102
 
103
  demo.launch()