Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,14 @@ from fastai.vision.all import *
|
|
| 5 |
from pathlib import Path
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Dictionary of plant names and their Wikipedia links
|
| 11 |
search_terms_wikipedia = {
|
|
@@ -120,15 +127,18 @@ def process_image(img, generate_image=True):
|
|
| 120 |
if generate_image:
|
| 121 |
prompt = random.choice(prompt_templates).format(flower=predicted_class)
|
| 122 |
|
|
|
|
|
|
|
|
|
|
| 123 |
# Use fal-client to generate image
|
| 124 |
-
result =
|
| 125 |
-
"fal-ai/flux/dev",
|
| 126 |
-
|
| 127 |
-
|
| 128 |
)
|
| 129 |
|
| 130 |
# Get the image from the result
|
| 131 |
-
image_base64 = result
|
| 132 |
image_bytes = base64.b64decode(image_base64)
|
| 133 |
generated_image = Image.open(io.BytesIO(image_bytes))
|
| 134 |
else:
|
|
|
|
| 5 |
from pathlib import Path
|
| 6 |
from PIL import Image
|
| 7 |
import io
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
# Importing fal-client
|
| 11 |
+
try:
|
| 12 |
+
from fal.client import Client as FalClient
|
| 13 |
+
except ImportError:
|
| 14 |
+
print("Error: fal-client module not found. Make sure it's in requirements.txt")
|
| 15 |
+
# Continue with a fallback if needed
|
| 16 |
|
| 17 |
# Dictionary of plant names and their Wikipedia links
|
| 18 |
search_terms_wikipedia = {
|
|
|
|
| 127 |
if generate_image:
|
| 128 |
prompt = random.choice(prompt_templates).format(flower=predicted_class)
|
| 129 |
|
| 130 |
+
# Initialize FAL Client
|
| 131 |
+
fal = FalClient(key=os.environ.get("FAL_KEY"))
|
| 132 |
+
|
| 133 |
# Use fal-client to generate image
|
| 134 |
+
result = fal.subscribe(
|
| 135 |
+
model_url="fal-ai/flux/dev",
|
| 136 |
+
prompt=prompt,
|
| 137 |
+
on_update=on_queue_update
|
| 138 |
)
|
| 139 |
|
| 140 |
# Get the image from the result
|
| 141 |
+
image_base64 = result.images[0]
|
| 142 |
image_bytes = base64.b64decode(image_base64)
|
| 143 |
generated_image = Image.open(io.BytesIO(image_bytes))
|
| 144 |
else:
|