Raumkommander commited on
Commit
85da776
·
1 Parent(s): a00d823

inital deployment1

Browse files
Files changed (2) hide show
  1. app.py +22 -34
  2. requirements.txt +2 -0
app.py CHANGED
@@ -8,30 +8,6 @@ import cv2
8
  import numpy as np
9
 
10
  # Function to process the video frame
11
- def process_frame(frame):
12
- # Convert frame to grayscale (example processing step)
13
- gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
14
- return gray_frame
15
-
16
- # Function to capture video feed
17
- def video_stream():
18
- cap = cv2.VideoCapture(0) # Open webcam
19
- while True:
20
- ret, frame = cap.read()
21
- if not ret:
22
- break
23
- processed_frame = process_frame(frame) # Apply processing
24
- yield processed_frame # Return processed frame
25
- cap.release()
26
-
27
- # Create the Gradio interface
28
- iface = gr.Interface(
29
- fn=video_stream,
30
- inputs=[],
31
- outputs=gr.Video(label="Webcam Feed"),
32
- live=True
33
- )
34
-
35
 
36
 
37
  # Load the pre-trained Real-Time LCM model
@@ -45,13 +21,25 @@ def generate_image(prompt: str):
45
  image = pipe(prompt, num_inference_steps=4).images[0]
46
  return image
47
 
48
- if __name__ == "__main__":
49
- iface.launch()
50
-
51
-
52
-
53
-
54
- # Launch the Gradio app
55
- if __name__ == "__main__":
56
- iface.launch(share=True)
57
-
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  import numpy as np
9
 
10
  # Function to process the video frame
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  # Load the pre-trained Real-Time LCM model
 
21
  image = pipe(prompt, num_inference_steps=4).images[0]
22
  return image
23
 
24
+ def process_frame(frame):
25
+ """Process each frame (convert to grayscale as an example)"""
26
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
27
+ return frame
28
+
29
+ def video_stream(frame):
30
+ """Receives video from webcam and processes it"""
31
+ if frame is None:
32
+ return None
33
+
34
+ frame = cv2.imdecode(np.frombuffer(frame, np.uint8), cv2.IMREAD_COLOR)
35
+ processed_frame = process_frame(frame)
36
+
37
+ return processed_frame
38
+
39
+ # Gradio Interface
40
+ iface = gr.Interface(
41
+ fn=video_stream,
42
+ inputs=gr.Video(source="webcam", streaming=True), # Connect local webcam
43
+ outputs=gr.Image(label="Processed Webcam Feed"), # Display processed frames
44
+ live=True
45
+ )
requirements.txt CHANGED
@@ -7,3 +7,5 @@ safetensors
7
  xformers
8
  torchvision
9
  opencv-python-headless
 
 
 
7
  xformers
8
  torchvision
9
  opencv-python-headless
10
+ opencv-python
11
+ numpy