Ahmed Faiyaz commited on
Commit
6654167
1 Parent(s): baeb4ed

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -0
app.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline
2
+ from typing import List, Optional, Tuple, Union
3
+ import torch
4
+ import gradio as gr
5
+ css="""
6
+ #input-panel{
7
+ align-items:center;
8
+ justify-content:center
9
+
10
+ }
11
+
12
+ """
13
+ pipeline = DiffusionPipeline.from_pretrained("gr33nr1ng3r/OkkhorDiffusion",custom_pipeline="gr33nr1ng3r/OkkhorDiffusion",embedding=torch.float16)
14
+ character_mappings = {
15
+ 'অ': 1,
16
+ 'আ': 2,
17
+ 'ই': 3,
18
+ 'ঈ': 4,
19
+ 'উ': 5,
20
+ 'ঊ': 6,
21
+ 'ঋ': 7,
22
+ 'এ': 8,
23
+ 'ঐ': 9,
24
+ 'ও': 10,
25
+ 'ঔ': 11,
26
+ 'ক': 12,
27
+ 'খ': 13,
28
+ 'গ': 14,
29
+ 'ঘ': 15,
30
+ 'ঙ': 16,
31
+ 'চ': 17,
32
+ 'ছ': 18,
33
+ 'জ': 19,
34
+ 'ঝ': 20,
35
+ 'ঞ': 21,
36
+ 'ট': 22,
37
+ 'ঠ': 23,
38
+ 'ড': 24,
39
+ 'ঢ': 25,
40
+ 'ণ': 26,
41
+ 'ত': 27,
42
+ 'থ': 28,
43
+ 'দ': 29,
44
+ 'ধ': 30,
45
+ 'ন': 31,
46
+ 'প': 32,
47
+ 'ফ': 33,
48
+ 'ব': 34,
49
+ 'ভ': 35,
50
+ 'ম': 36,
51
+ 'য': 37,
52
+ 'র': 38,
53
+ 'ল': 39,
54
+ 'শ': 40,
55
+ 'ষ': 41,
56
+ 'স': 42,
57
+ 'হ': 43,
58
+ 'ড়': 44,
59
+ 'ঢ়': 45,
60
+ 'য়': 46,
61
+ 'ৎ': 47,
62
+ 'ং': 48,
63
+ 'ঃ': 49,
64
+ 'ঁ': 50,
65
+ '০': 51,
66
+ '১': 52,
67
+ '২': 53,
68
+ '৩': 54,
69
+ '৪': 55,
70
+ '৫': 56,
71
+ '৬': 57,
72
+ '৭': 58,
73
+ '৮': 59,
74
+ '৯': 60,
75
+ 'ক্ষ(ksa)': 61,
76
+ 'ব্দ(bda)': 62,
77
+ 'ঙ্গ': 63,
78
+ 'স্ক': 64,
79
+ 'স্ফ': 65,
80
+ 'স্থ': 66,
81
+ 'চ্ছ': 67,
82
+ 'ক্ত': 68,
83
+ 'স্ন': 69,
84
+ 'ষ্ণ': 70,
85
+ 'ম্প': 71,
86
+ 'হ্ম': 72,
87
+ 'প্ত': 73,
88
+ 'ম্ব': 74,
89
+ 'ন্ড': 75,
90
+ 'দ্ভ': 76,
91
+ 'ত্থ': 77,
92
+ 'ষ্ঠ': 78,
93
+ 'ল্প': 79,
94
+ 'ষ্প': 80,
95
+ 'ন্দ': 81,
96
+ 'ন্ধ': 82,
97
+ 'ম্ম': 83,
98
+ 'ন্ঠ': 84,
99
+ }
100
+
101
+ def generate(input_text:str,batch_size:int,inference_steps:int):
102
+ batch_size=int(batch_size)
103
+ inference_steps=int(inference_steps)
104
+ print(f"Generating image with label:{character_mappings[input_text]} batch size:{batch_size}")
105
+ label=int(character_mappings[input_text])
106
+ pipeline.embedding=torch.tensor([label])
107
+ generate_image=pipeline(batch_size=batch_size,num_inference_steps=inference_steps).images
108
+ return generate_image
109
+
110
+
111
+
112
+ with gr.Blocks(css=css,elem_id="panel") as od_app:
113
+ with gr.Column(min_width=100):
114
+ text=gr.HTML("""
115
+ <div style="text-align: center; margin: 0 auto;">
116
+ <div style="display: inline-flex;align-items: center;gap: 0.8rem;font-size: 1.75rem;">
117
+ <h1> Okkhor Diffusion </h1>
118
+ </div>
119
+ </div>
120
+
121
+ """)
122
+ #input panel
123
+
124
+ with gr.Row(elem_id="input-panel"):
125
+ with gr.Column(variant="panel",scale=0,elem_id="input-panel-items"):
126
+ dropdown = gr.Dropdown(label="Select Character",choices=list(character_mappings.keys()))
127
+ batch_size = gr.Number(label="Batch Size", minimum=0, maximum=100)
128
+ inference_steps= gr.Slider(label="Steps",value=100,minimum=100,maximum=1000,step=100)
129
+ btn = gr.Button("Generate",size="sm")
130
+
131
+
132
+ gallery = gr.Gallery(
133
+ label="Generated images", show_label=False, elem_id="gallery"
134
+ , columns=[10], rows=[10], object_fit="contain", height="auto",scale=1,min_width=80)
135
+
136
+
137
+ btn.click(fn=generate,inputs=[dropdown,batch_size,inference_steps],outputs=[gallery])
138
+
139
+ if __name__=='__main__':
140
+ od_app.queue(max_size=20).launch(show_error=True)
141
+
142
+
143
+
144
+
145
+