codermert commited on
Commit
f4f5632
·
verified ·
1 Parent(s): ed70c82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -120
app.py CHANGED
@@ -1,127 +1,33 @@
1
  import gradio as gr
2
- import numpy as np
3
- import random
4
- import spaces
5
- import torch
6
- from diffusers import DiffusionPipeline
7
 
8
- dtype = torch.bfloat16
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
- pipe = DiffusionPipeline.from_pretrained("codermert/zehra_flux", torch_dtype=dtype).to(device)
11
- MAX_SEED = np.iinfo(np.int32).max
12
- MAX_IMAGE_SIZE = 2048
13
 
14
- @spaces.GPU()
15
- def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, num_images=4, progress=gr.Progress(track_tqdm=True)):
16
- if randomize_seed:
17
- seed = random.randint(0, MAX_SEED)
18
-
19
- generator = torch.Generator().manual_seed(seed)
20
- images = []
21
-
22
- for _ in range(num_images):
23
- image = pipe(
24
- prompt=prompt,
25
- width=width,
26
- height=height,
27
- num_inference_steps=num_inference_steps,
28
- generator=generator,
29
- guidance_scale=0.0
30
- ).images[0]
31
- images.append(image)
32
- # Her görsel için farklı seed kullan
33
- seed = random.randint(0, MAX_SEED)
34
- generator = torch.Generator().manual_seed(seed)
35
-
36
- return images, seed
37
 
38
- examples = [
39
- "a tiny astronaut hatching from an egg on the moon",
40
- "a cat holding a sign that says hello world",
41
- "an anime illustration of a wiener schnitzel",
42
- ]
 
 
43
 
44
- css = """
45
- #col-container {
46
- margin: 0 auto;
47
- max-width: 900px;
48
- }
49
- .generated-images {
50
- display: grid;
51
- grid-template-columns: repeat(2, 1fr);
52
- gap: 10px;
53
- }
54
- """
55
 
56
- with gr.Blocks(css=css) as demo:
57
- with gr.Column(elem_id="col-container"):
58
- gr.Markdown("""# Zehra Flux Image Generator
59
- 4 farklı görsel üreten AI görsel oluşturucu
60
- """)
61
-
62
- with gr.Row():
63
- prompt = gr.Text(
64
- label="Prompt",
65
- show_label=False,
66
- max_lines=1,
67
- placeholder="Görseliniz için prompt girin",
68
- container=False,
69
- )
70
- run_button = gr.Button("Oluştur", scale=0)
71
-
72
- # 4 görsel için grid layout
73
- with gr.Row(elem_classes="generated-images"):
74
- results = [gr.Image(label=f"Sonuç {i+1}", show_label=True) for i in range(4)]
75
-
76
- with gr.Accordion("Gelişmiş Ayarlar", open=False):
77
- seed = gr.Slider(
78
- label="Seed",
79
- minimum=0,
80
- maximum=MAX_SEED,
81
- step=1,
82
- value=0,
83
- )
84
-
85
- randomize_seed = gr.Checkbox(label="Rastgele seed", value=True)
86
-
87
- with gr.Row():
88
- width = gr.Slider(
89
- label="Genişlik",
90
- minimum=256,
91
- maximum=MAX_IMAGE_SIZE,
92
- step=32,
93
- value=1024,
94
- )
95
-
96
- height = gr.Slider(
97
- label="Yükseklik",
98
- minimum=256,
99
- maximum=MAX_IMAGE_SIZE,
100
- step=32,
101
- value=1024,
102
- )
103
-
104
- num_inference_steps = gr.Slider(
105
- label="Inference adım sayısı",
106
- minimum=1,
107
- maximum=50,
108
- step=1,
109
- value=4,
110
- )
111
-
112
- gr.Examples(
113
- examples=examples,
114
- fn=infer,
115
- inputs=[prompt],
116
- outputs=[*results, seed],
117
- cache_examples="lazy"
118
- )
119
-
120
- gr.on(
121
- triggers=[run_button.click, prompt.submit],
122
- fn=infer,
123
- inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
124
- outputs=[*results, seed]
125
- )
126
 
127
- demo.launch()
 
 
 
1
  import gradio as gr
 
 
 
 
 
2
 
3
+ from infer import infer_image, infer_video
 
 
 
 
4
 
5
+ input_image = gr.Image(type='pil', label='Input Image')
6
+ input_model_image = gr.Radio([('x2', 2), ('x4', 4), ('x8', 8)], type="value", value=4, label="Model Upscale/Enhance Type")
7
+ submit_image_button = gr.Button('Submit')
8
+ output_image = gr.Image(type="filepath", label="Output Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ tab_img = gr.Interface(
11
+ fn=infer_image,
12
+ inputs=[input_image, input_model_image],
13
+ outputs=output_image,
14
+ title="Real-ESRGAN Pytorch",
15
+ description="Gradio UI for Real-ESRGAN Pytorch version. To use it, simply upload your image and choose the model. Read more at the links below. Please click submit only once <br>Credits: [Nick088](https://linktr.ee/Nick088), Xinntao, Tencent, Geeve George, ai-forever, daroche <br><p style='text-align: center'><a href='https://github.com/Nick088/Real-ESRGAN_Pytorch'>Github Repo</a></p>"
16
+ )
17
 
18
+ input_video = gr.Video(label='Input Video')
19
+ input_model_video = gr.Radio([('x2', 2), ('x4', 4), ('x8', 8)], type="value", value=2, label="Model Upscale/Enhance Type")
20
+ submit_video_button = gr.Button('Submit')
21
+ output_video = gr.Video(label='Output Video')
 
 
 
 
 
 
 
22
 
23
+ tab_vid = gr.Interface(
24
+ fn=infer_video,
25
+ inputs=[input_video, input_model_video],
26
+ outputs=output_video,
27
+ title="Real-ESRGAN Pytorch",
28
+ description="Gradio UI for Real-ESRGAN Pytorch version. To use it, simply upload your video and choose the model. Read more at the links below. Please click submit only once <br>Credits: [Nick088](https://linktr.ee/Nick088), Xinntao, Tencent, Geeve George, ai-forever, daroche <br><p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/ai-forever/Real-ESRGAN'>Github Repo</a></p>"
29
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ demo = gr.TabbedInterface([tab_img, tab_vid], ["Image", "Video"])
32
+
33
+ demo.launch(debug=True, show_error=True, share=True)