Ashrafb commited on
Commit
b56f39c
โ€ข
1 Parent(s): 4967a1a

Upload app (3).py

Browse files
Files changed (1) hide show
  1. app (3).py +122 -0
app (3).py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import sys
4
+ import random
5
+ import string
6
+ import time
7
+ from queue import Queue
8
+ from threading import Thread
9
+
10
+
11
+ proc1 = gr.Interface.load("models/segmind/SSD-1B")
12
+
13
+ def restart_script_periodically():
14
+ while True:
15
+ random_time = random.randint(540, 600)
16
+ time.sleep(random_time)
17
+ os.execl(sys.executable, sys.executable, *sys.argv)
18
+
19
+ restart_thread = Thread(target=restart_script_periodically, daemon=True)
20
+ restart_thread.start()
21
+
22
+ queue = Queue()
23
+ queue_threshold = 100
24
+
25
+ def add_random_noise(prompt, noise_level=0.00):
26
+ if noise_level == 0:
27
+ noise_level = 0.00
28
+ percentage_noise = noise_level * 5
29
+ num_noise_chars = int(len(prompt) * (percentage_noise / 100))
30
+ noise_indices = random.sample(range(len(prompt)), num_noise_chars)
31
+ prompt_list = list(prompt)
32
+ noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
33
+ noise_chars.extend(['๐Ÿ˜', '๐Ÿ’ฉ', '๐Ÿ˜‚', '๐Ÿค”', '๐Ÿ˜Š', '๐Ÿค—', '๐Ÿ˜ญ', '๐Ÿ™„', '๐Ÿ˜ท', '๐Ÿคฏ', '๐Ÿคซ', '๐Ÿฅด', '๐Ÿ˜ด', '๐Ÿคฉ', '๐Ÿฅณ', '๐Ÿ˜”', '๐Ÿ˜ฉ', '๐Ÿคช', '๐Ÿ˜‡', '๐Ÿคข', '๐Ÿ˜ˆ', '๐Ÿ‘น', '๐Ÿ‘ป', '๐Ÿค–', '๐Ÿ‘ฝ', '๐Ÿ’€', '๐ŸŽƒ', '๐ŸŽ…', '๐ŸŽ„', '๐ŸŽ', '๐ŸŽ‚', '๐ŸŽ‰', '๐ŸŽˆ', '๐ŸŽŠ', '๐ŸŽฎ', 'โค๏ธ', '๐Ÿ’”', '๐Ÿ’•', '๐Ÿ’–', '๐Ÿ’—', '๐Ÿถ', '๐Ÿฑ', '๐Ÿญ', '๐Ÿน', '๐ŸฆŠ', '๐Ÿป', '๐Ÿจ', '๐Ÿฏ', '๐Ÿฆ', '๐Ÿ˜', '๐Ÿ”ฅ', '๐ŸŒง๏ธ', '๐ŸŒž', '๐ŸŒˆ', '๐Ÿ’ฅ', '๐ŸŒด', '๐ŸŒŠ', '๐ŸŒบ', '๐ŸŒป', '๐ŸŒธ', '๐ŸŽจ', '๐ŸŒ…', '๐ŸŒŒ', 'โ˜๏ธ', 'โ›ˆ๏ธ', 'โ„๏ธ', 'โ˜€๏ธ', '๐ŸŒค๏ธ', 'โ›…๏ธ', '๐ŸŒฅ๏ธ', '๐ŸŒฆ๏ธ', '๐ŸŒง๏ธ', '๐ŸŒฉ๏ธ', '๐ŸŒจ๏ธ', '๐ŸŒซ๏ธ', 'โ˜”๏ธ', '๐ŸŒฌ๏ธ', '๐Ÿ’จ', '๐ŸŒช๏ธ', '๐ŸŒˆ'])
34
+ for index in noise_indices:
35
+ prompt_list[index] = random.choice(noise_chars)
36
+ return "".join(prompt_list)
37
+
38
+ # Existing code...
39
+
40
+ import uuid # Import the UUID library
41
+
42
+ # Existing code...
43
+
44
+ # Existing code...
45
+
46
+ request_counter = 0 # Global counter to track requests
47
+ # Defining the image styles and default style
48
+ IMAGE_STYLES = [
49
+ "No style",
50
+ "Cinematic",
51
+ "Photographic",
52
+ "Anime",
53
+ "Manga",
54
+ "Digital Art",
55
+ "Pixel art",
56
+ "Fantasy art",
57
+ "Neonpunk",
58
+ "3D Model"
59
+ ]
60
+
61
+ DEFAULT_IMAGE_STYLE = "Cinematic"
62
+
63
+
64
+ def send_it1(inputs, noise_level, style, proc=proc1):
65
+ global request_counter
66
+ request_counter += 1
67
+ timestamp = f"{time.time()}_{request_counter}"
68
+ advanced_options = f"\nStyle: {style}\n"
69
+ prompt_with_noise = add_random_noise(inputs, noise_level) + f" - {timestamp}"+ advanced_options
70
+ while queue.qsize() >= queue_threshold:
71
+ time.sleep(2)
72
+ queue.put(prompt_with_noise)
73
+ output = proc(prompt_with_noise)
74
+ return output
75
+
76
+
77
+ # ... (existing code)
78
+
79
+ # ... (existing code)
80
+
81
+ with gr.Blocks(css=".gradio-container {background-color: #fdf7e6;} footer{display:none !important;}",) as demo:
82
+
83
+
84
+
85
+ with gr.Column(elem_id="col-container"):
86
+
87
+ with gr.Row(variant="compact"):
88
+ prompt = gr.Textbox(
89
+ lines=8,
90
+ label="Enter your prompt",
91
+ show_label=False,
92
+ max_lines=10,
93
+ placeholder="Full Prompt",
94
+ ).style(
95
+ container=False,
96
+ textarea={'height': '400px'}
97
+ )
98
+
99
+ run = gr.Button("Generate Images").style(full_width=False)
100
+ with gr.Accordion("Advanced options", open=False):
101
+ with gr.Row():
102
+ style_selection = gr.Radio(
103
+ show_label=True, container=True, interactive=True,
104
+ choices=IMAGE_STYLES,
105
+ value=DEFAULT_IMAGE_STYLE,
106
+ label='Image Style'
107
+ )
108
+
109
+ with gr.Row():
110
+ with gr.Row():
111
+ noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Noise Level")
112
+
113
+ with gr.Row():
114
+ with gr.Row():
115
+ output1 = gr.Image(label="", show_label=False, show_share_button=False)
116
+ output2 = gr.Image(label="", show_label=False, show_share_button=False)
117
+
118
+ # Adjust the click event to include the style_selection Radio component
119
+ run.click(send_it1, inputs=[prompt, noise_level, style_selection], outputs=[output1])
120
+ run.click(send_it1, inputs=[prompt, noise_level, style_selection], outputs=[output2])
121
+
122
+ demo.launch(enable_queue=True, inline=True)