Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,9 @@ import numpy as np
|
|
4 |
import random
|
5 |
import spaces
|
6 |
import torch
|
|
|
|
|
|
|
7 |
import os
|
8 |
|
9 |
token = os.environ["API_TOKEN"]
|
@@ -17,9 +20,14 @@ MAX_IMAGE_SIZE = 2048
|
|
17 |
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
18 |
if randomize_seed:
|
19 |
seed = random.randint(0, MAX_SEED)
|
20 |
-
|
21 |
-
image =
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
examples = [
|
25 |
"a tiny astronaut hatching from an egg on the moon",
|
|
|
4 |
import random
|
5 |
import spaces
|
6 |
import torch
|
7 |
+
import tempfile
|
8 |
+
import os
|
9 |
+
from PIL import Image
|
10 |
import os
|
11 |
|
12 |
token = os.environ["API_TOKEN"]
|
|
|
20 |
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
21 |
if randomize_seed:
|
22 |
seed = random.randint(0, MAX_SEED)
|
23 |
+
model = InferenceClient("black-forest-labs/FLUX.1-schnell", token=prompt)
|
24 |
+
image = model(prompt)
|
25 |
+
temp_dir = tempfile.gettempdir()
|
26 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".jpg", dir=temp_dir)
|
27 |
+
image.save(temp_file, format="JPEG")
|
28 |
+
temp_file_path = temp_file.name
|
29 |
+
temp_file.close()
|
30 |
+
return temp_file_path, seed
|
31 |
|
32 |
examples = [
|
33 |
"a tiny astronaut hatching from an egg on the moon",
|