Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,10 @@ from random import randint
|
|
3 |
from all_models import models
|
4 |
from externalmod import gr_Interface_load
|
5 |
import asyncio
|
|
|
6 |
from threading import RLock
|
7 |
lock = RLock()
|
|
|
8 |
|
9 |
|
10 |
def load_fn(models):
|
@@ -13,7 +15,7 @@ def load_fn(models):
|
|
13 |
for model in models:
|
14 |
if model not in models_load.keys():
|
15 |
try:
|
16 |
-
m = gr_Interface_load(f'models/{model}')
|
17 |
except Exception as error:
|
18 |
print(error)
|
19 |
m = gr.Interface(lambda: None, ['text'], ['image'])
|
@@ -52,7 +54,7 @@ async def infer(model_str, prompt, nprompt="", height=None, width=None, steps=No
|
|
52 |
for i in range(rand):
|
53 |
noise += " "
|
54 |
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
|
55 |
-
prompt=f'{prompt} {noise}', negative_prompt=nprompt, **kwargs))
|
56 |
await asyncio.sleep(0)
|
57 |
try:
|
58 |
result = await asyncio.wait_for(task, timeout=timeout)
|
|
|
3 |
from all_models import models
|
4 |
from externalmod import gr_Interface_load
|
5 |
import asyncio
|
6 |
+
import os
|
7 |
from threading import RLock
|
8 |
lock = RLock()
|
9 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") if os.environ.get("HF_TOKEN") else None
|
10 |
|
11 |
|
12 |
def load_fn(models):
|
|
|
15 |
for model in models:
|
16 |
if model not in models_load.keys():
|
17 |
try:
|
18 |
+
m = gr_Interface_load(f'models/{model}', hf_token=HF_TOKEN)
|
19 |
except Exception as error:
|
20 |
print(error)
|
21 |
m = gr.Interface(lambda: None, ['text'], ['image'])
|
|
|
54 |
for i in range(rand):
|
55 |
noise += " "
|
56 |
task = asyncio.create_task(asyncio.to_thread(models_load[model_str].fn,
|
57 |
+
prompt=f'{prompt} {noise}', negative_prompt=nprompt, **kwargs, token=HF_TOKEN))
|
58 |
await asyncio.sleep(0)
|
59 |
try:
|
60 |
result = await asyncio.wait_for(task, timeout=timeout)
|