Tramac commited on
Commit
4c7447e
1 Parent(s): 9d5045e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -1
app.py CHANGED
@@ -1,3 +1,53 @@
 
 
1
  import gradio as gr
2
 
3
- gr.load("models/Tramac/style-portrait-v1-5").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import spaces
3
  import gradio as gr
4
 
5
+ from diffusers import StableDiffusionPipeline
6
+
7
+
8
+ repo = "Tramac/style-portrait-v1-5"
9
+ # Ensure model and scheduler are initialized in GPU-enabled function
10
+ if torch.cuda.is_available():
11
+ pipeline = StableDiffusionPipeline.from_pretrained(
12
+ repo,
13
+ torch_dtype=torch.float16,
14
+ variant="fp16"
15
+ ).to("cuda")
16
+
17
+ @spaces.GPU(enable_queue=True)
18
+ def generate_image(prompt, neg_prompt):
19
+ results = pipe(
20
+ prompt=prompt,
21
+ negative_prompt=neg_prompt,
22
+ height=832,
23
+ width=512,
24
+ num_inference_steps=20,
25
+ )
26
+ return results.images[0]
27
+
28
+
29
+
30
+ with gr.Blocks() as demo:
31
+ gr.HTML("<h1><center>Style Portrait</center></h1>")
32
+ gr.HTML("<p><center>text-to-image generation</center></p><p><center><a href='https://huggingface.co/Tramac/style-portrait-v1-5'></a></center></p>")
33
+ with gr.Row():
34
+ with gr.Column():
35
+ prompt = gr.Textbox(label='Enter your prompt', scale=8)
36
+ neg_prompt = gr.Textbox(label='Enter your negative prompt', scale=8)
37
+ submit = gr.Button(scale=1, variant='primary')
38
+
39
+ with gr.Column():
40
+ img = gr.Image(label='Style-Portrait Generated Image')
41
+
42
+ prompt.submit(
43
+ fn=generate_image,
44
+ inputs=[prompt, neg_prompt],
45
+ outputs=img,
46
+ )
47
+ submit.click(
48
+ fn=generate_image,
49
+ inputs=[prompt, neg_prompt],
50
+ outputs=img,
51
+ )
52
+
53
+ demo.queue().launch(share=True)