Spaces:
Sleeping
Sleeping
adding scheduler
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from utils import load_model, generate_random_img
|
|
|
|
|
|
|
|
|
4 |
|
5 |
def generate_image():
|
6 |
with torch.no_grad():
|
@@ -18,5 +22,7 @@ iface = gr.Interface(
|
|
18 |
css='img_styles.css',
|
19 |
)
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from utils import load_model, generate_random_img, schedule_function
|
4 |
+
import time
|
5 |
+
import random
|
6 |
+
import threading
|
7 |
+
from gradio_client import Client
|
8 |
|
9 |
def generate_image():
|
10 |
with torch.no_grad():
|
|
|
22 |
css='img_styles.css',
|
23 |
)
|
24 |
|
25 |
+
if __name__ == '__main__':
|
26 |
+
scheduler_thread = threading.Thread(target=schedule_function) # avoiding sleep, again this project is for academic purposes only
|
27 |
+
scheduler_thread.start()
|
28 |
+
iface.launch()
|
utils.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
3 |
|
4 |
import torch
|
5 |
import torchvision
|
@@ -142,6 +144,19 @@ def generate_random_img(model):
|
|
142 |
|
143 |
return generated_image
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
if __name__ == "__main__":
|
146 |
model = load_model('generator','generator_model_epoch_94.pth')
|
147 |
generate_random_img(model)
|
|
|
1 |
+
import time
|
2 |
+
import random
|
3 |
+
import threading
|
4 |
+
from gradio_client import Client
|
5 |
|
6 |
import torch
|
7 |
import torchvision
|
|
|
144 |
|
145 |
return generated_image
|
146 |
|
147 |
+
def schedule_function(): # for dummy space so that this spcae and other space will call each other to avoid sleep time, again this project is for academic purpose.
|
148 |
+
while True:
|
149 |
+
# wait_time = random.uniform(3 * 60 * 60, 5 * 60 * 60) # Get a random wait time between 3 and 5 hours in seconds
|
150 |
+
wait_time = random.uniform(3, 5)
|
151 |
+
time.sleep(wait_time)
|
152 |
+
# call dummyscape
|
153 |
+
client = Client("https://huseyng-dummyspace.hf.space/")
|
154 |
+
result = client.predict(
|
155 |
+
f"Howdy! {wait_time}", # str representing string value in 'name' Textbox component
|
156 |
+
api_name="/predict"
|
157 |
+
)
|
158 |
+
print(result)
|
159 |
+
|
160 |
if __name__ == "__main__":
|
161 |
model = load_model('generator','generator_model_epoch_94.pth')
|
162 |
generate_random_img(model)
|