Raumkommander commited on
Commit
f1e3f4b
·
1 Parent(s): e1cf579

inital deployment1

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -3,11 +3,12 @@ import cv2
3
  import torch
4
  import numpy as np
5
  from diffusers import StableDiffusionImg2ImgPipeline
 
6
  from PIL import Image
7
 
8
- # Load the Stable Diffusion Model
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion-v1-5").to(device)
11
 
12
  def apply_color_filter(frame, filter_type="None"):
13
  """Apply a color filter to the frame."""
@@ -23,14 +24,14 @@ def apply_color_filter(frame, filter_type="None"):
23
  return frame
24
 
25
  def process_frame(frame, filter_type="None", prompt="A futuristic landscape"):
26
- """Process a single frame by applying a color filter and diffusion model."""
27
  frame = apply_color_filter(frame, filter_type)
28
 
29
  # Convert frame to PIL image
30
  image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).resize((512, 512))
31
 
32
- # Apply Stable Diffusion model
33
- result = pipe(prompt=prompt, image=image, strength=0.5, guidance_scale=7.5).images[0]
34
  return np.array(result)
35
 
36
  def video_stream(filter_type, prompt):
@@ -45,21 +46,17 @@ def video_stream(filter_type, prompt):
45
  yield frame # Return processed frame
46
  cap.release()
47
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
-
50
-
51
-
52
- iface = gr.Interface(
53
- fn=video_stream,
54
- inputs=[
55
- gr.Video( streaming=True), # Use browser webcam
56
- gr.Radio(["None", "Red", "Green", "Blue"], label="Color Filter"),
57
- gr.Textbox(label="Stable Diffusion Prompt", value="A futuristic landscape"),
58
- ],
59
- outputs=gr.Image(label="AI-Enhanced Webcam Feed"),
60
- live=True,
61
- )
62
-
63
-
64
- if __name__ == "__main__":
65
- iface.launch(share=True)
 
3
  import torch
4
  import numpy as np
5
  from diffusers import StableDiffusionImg2ImgPipeline
6
+ from transformers import AutoProcessor, AutoModel
7
  from PIL import Image
8
 
9
+ # Load the Real-Time Latent Consistency Model
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
+ realtime_pipe = StableDiffusionImg2ImgPipeline.from_pretrained("radames/Real-Time-Latent-Consistency-Model").to(device)
12
 
13
  def apply_color_filter(frame, filter_type="None"):
14
  """Apply a color filter to the frame."""
 
24
  return frame
25
 
26
  def process_frame(frame, filter_type="None", prompt="A futuristic landscape"):
27
+ """Process a single frame by applying a color filter and real-time latent consistency model."""
28
  frame = apply_color_filter(frame, filter_type)
29
 
30
  # Convert frame to PIL image
31
  image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).resize((512, 512))
32
 
33
+ # Apply Real-Time Latent Consistency Model
34
+ result = realtime_pipe(prompt=prompt, image=image, strength=0.5, guidance_scale=7.5).images[0]
35
  return np.array(result)
36
 
37
  def video_stream(filter_type, prompt):
 
46
  yield frame # Return processed frame
47
  cap.release()
48
 
49
+ # Create Gradio App
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown("## 🎨 Real-Time AI-Enhanced Webcam using Latent Consistency Model")
52
+
53
+ with gr.Row():
54
+ webcam_feed = gr.Camera(streaming=True, label="Live Webcam")
55
+ processed_image = gr.Image(label="AI-Enhanced Webcam Feed")
56
+
57
+ filter_selector = gr.Radio(["None", "Red", "Green", "Blue"], label="Color Filter")
58
+ prompt_input = gr.Textbox(label="Real-Time Latent Consistency Model Prompt", value="A futuristic landscape")
59
+
60
+ webcam_feed.change(fn=video_stream, inputs=[filter_selector, prompt_input], outputs=processed_image)
61
 
62
+ demo.launch(share=True)