wifix199 commited on
Commit
d709633
·
verified ·
1 Parent(s): f8381c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -1,24 +1,33 @@
1
- from diffusers import StableDiffusionPipeline
2
  import torch
 
3
  import gradio as gr
4
 
5
- # Load the model (assuming it uses the Stable Diffusion architecture)
6
- model_id = "Shakker-Labs/AWPortrait-FL"
7
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
8
- pipe.to("cpu") # Use "cuda" if you have a GPU
9
 
10
- # Generate an image from a text prompt
11
  def generate_image(prompt):
12
- image = pipe(prompt).images[0]
 
 
 
 
13
  return image
14
-
15
- # Define the function to generate the image
16
- def chatbot_image(prompt):
17
  image = generate_image(prompt)
18
  return image
19
 
20
- # Create a Gradio interface
21
- interface = gr.Interface(fn=chatbot_image, inputs="text", outputs="image", title="Text-to-Image Chatbot")
 
 
 
 
 
 
22
 
23
- # Launch the interface
24
- interface.launch()
 
 
1
  import torch
2
+ from diffusers import FluxPipeline
3
  import gradio as gr
4
 
5
+ # Load the model and set to CPU
6
+ pipe = FluxPipeline.from_pretrained("Shakker-Labs/AWPortrait-FL", torch_dtype=torch.float32)
7
+ pipe.to("cpu") # Set to CPU
 
8
 
9
+ # Define the function to generate an image from a given prompt
10
  def generate_image(prompt):
11
+ image = pipe(prompt,
12
+ num_inference_steps=24,
13
+ guidance_scale=3.5,
14
+ width=768, height=1024).images[0]
15
+ image.save(f"example.png")
16
  return image
17
+
18
+ # Create a Gradio interface
19
+ def inference(prompt):
20
  image = generate_image(prompt)
21
  return image
22
 
23
+ # Gradio Interface
24
+ interface = gr.Interface(
25
+ fn=inference,
26
+ inputs=gr.Textbox(lines=2, placeholder="Enter your image description here..."),
27
+ outputs="image",
28
+ title="Text-to-Image Generator",
29
+ description="Enter a text prompt to generate an image using AWPortrait-FL."
30
+ )
31
 
32
+ # Launch the Gradio interface
33
+ interface.launch()