LuigiLui commited on
Commit
e816365
·
verified ·
1 Parent(s): d1e175c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -1,17 +1,14 @@
1
  import gradio as gr
2
  import random
3
- import torch # Assuming your model is compatible with PyTorch for GPU use
4
 
5
- # Load the model once at startup (GPU-optimized if available)
6
- device = "cuda" if torch.cuda.is_available() else "cpu"
7
- model = gr.load("models/Purz/face-projection").to(device)
8
 
9
- # Function to generate the image
10
  def generate_image(text, seed):
11
  if seed is not None:
12
  random.seed(seed)
13
- # Generate image using the model, ensure device compatibility
14
- return model(text).to("cpu") # Move to CPU if Gradio doesn't support GPU display
15
 
16
  # Define example inputs
17
  examples = [
@@ -21,7 +18,7 @@ examples = [
21
  ["Fantasy dragon", None]
22
  ]
23
 
24
- # Customized Gradio Interface with faster processing optimizations
25
  interface = gr.Interface(
26
  fn=generate_image,
27
  inputs=[
@@ -31,7 +28,7 @@ interface = gr.Interface(
31
  outputs=gr.Image(label="Generated Image", elem_id="output-image"),
32
  examples=examples,
33
  theme="default",
34
- description="The model is currently running on GPU for faster processing. Thanks for your patience.",
35
  css="""
36
  #input-text, #seed-slider .input-label, .output-label, .description {
37
  font-family: 'Arial', sans-serif;
 
1
  import gradio as gr
2
  import random
 
3
 
4
+ # Load the model
5
+ model = gr.load("models/Purz/face-projection")
 
6
 
7
+ # Function to generate image
8
  def generate_image(text, seed):
9
  if seed is not None:
10
  random.seed(seed)
11
+ return model(text)
 
12
 
13
  # Define example inputs
14
  examples = [
 
18
  ["Fantasy dragon", None]
19
  ]
20
 
21
+ # Customized Gradio Interface
22
  interface = gr.Interface(
23
  fn=generate_image,
24
  inputs=[
 
28
  outputs=gr.Image(label="Generated Image", elem_id="output-image"),
29
  examples=examples,
30
  theme="default",
31
+ description="The model is currently running on CPU. Performance might vary. Thanks for your patience.",
32
  css="""
33
  #input-text, #seed-slider .input-label, .output-label, .description {
34
  font-family: 'Arial', sans-serif;