Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,13 @@ import gradio as gr
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
def load_fn(models):
|
@@ -11,9 +18,10 @@ def load_fn(models):
|
|
11 |
for model in models:
|
12 |
if model not in models_load.keys():
|
13 |
try:
|
14 |
-
m =
|
15 |
except Exception as error:
|
16 |
-
|
|
|
17 |
models_load.update({model: m})
|
18 |
|
19 |
|
@@ -22,17 +30,16 @@ load_fn(models)
|
|
22 |
|
23 |
num_models = 2
|
24 |
default_models = models[:num_models]
|
25 |
-
|
26 |
|
27 |
|
28 |
def extend_choices(choices):
|
29 |
-
return choices + (num_models - len(choices)) * ['NA']
|
30 |
|
31 |
|
32 |
def update_imgbox(choices):
|
33 |
-
choices_plus = extend_choices(choices)
|
34 |
-
return [gr.Image(None, label
|
35 |
-
|
36 |
|
37 |
def gen_fn(model_str, prompt):
|
38 |
if model_str == 'NA':
|
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
|
5 |
+
from externalmod import gr_Interface_load
|
6 |
+
|
7 |
+
import asyncio
|
8 |
+
import os
|
9 |
+
from threading import RLock
|
10 |
+
lock = RLock()
|
11 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None # If private or gated models aren't used, ENV setting is unnecessary.
|
12 |
|
13 |
|
14 |
def load_fn(models):
|
|
|
18 |
for model in models:
|
19 |
if model not in models_load.keys():
|
20 |
try:
|
21 |
+
m = gr_Interface_load(f'models/{model}', hf_token=HF_TOKEN)
|
22 |
except Exception as error:
|
23 |
+
print(error)
|
24 |
+
m = gr.Interface(lambda: None, ['text'], ['image'])
|
25 |
models_load.update({model: m})
|
26 |
|
27 |
|
|
|
30 |
|
31 |
num_models = 2
|
32 |
default_models = models[:num_models]
|
33 |
+
inference_timeout = 600
|
34 |
|
35 |
|
36 |
def extend_choices(choices):
|
37 |
+
return choices[:num_models] + (num_models - len(choices[:num_models])) * ['NA']
|
38 |
|
39 |
|
40 |
def update_imgbox(choices):
|
41 |
+
choices_plus = extend_choices(choices[:num_models])
|
42 |
+
return [gr.Image(None, label=m, visible=(m!='NA')) for m in choices_plus]
|
|
|
43 |
|
44 |
def gen_fn(model_str, prompt):
|
45 |
if model_str == 'NA':
|