Michael Krasa
commited on
Commit
·
e9c62c9
1
Parent(s):
2036d98
fixed prediction, removed example images
Browse files- Brittlebush-Encelia-Farinosa-desert-horizon-nursery.jpg +0 -3
- app.py +4 -6
- download.webp +0 -0
Brittlebush-Encelia-Farinosa-desert-horizon-nursery.jpg
DELETED
Git LFS Details
|
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import gradio as gr
|
|
| 3 |
import fal_client
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
-
import base64
|
| 7 |
import random
|
| 8 |
import requests
|
| 9 |
|
|
@@ -52,11 +51,10 @@ def on_queue_update(update):
|
|
| 52 |
|
| 53 |
def process_image(img):
|
| 54 |
# First do the classification
|
| 55 |
-
|
| 56 |
-
classification_results = dict(zip(
|
| 57 |
|
| 58 |
# Get Wikipedia URL for the predicted class
|
| 59 |
-
predicted_class = max(classification_results.items(), key=lambda x: x[1])[0]
|
| 60 |
wiki_url = search_terms_wikipedia.get(predicted_class, "No Wikipedia entry found.")
|
| 61 |
|
| 62 |
# Generate FLUX image
|
|
@@ -64,7 +62,7 @@ def process_image(img):
|
|
| 64 |
"fal-ai/flux/schnell",
|
| 65 |
arguments={
|
| 66 |
"prompt": random.choice(prompt_templates).format(flower=predicted_class),
|
| 67 |
-
"image_size": "
|
| 68 |
},
|
| 69 |
with_logs=True,
|
| 70 |
on_queue_update=on_queue_update,
|
|
@@ -101,7 +99,7 @@ with gr.Blocks() as demo:
|
|
| 101 |
gr.Examples(
|
| 102 |
examples=examples,
|
| 103 |
inputs=input_image,
|
| 104 |
-
examples_per_page=
|
| 105 |
fn=process_image,
|
| 106 |
outputs=[label_output, generated_image, wiki_output]
|
| 107 |
)
|
|
|
|
| 3 |
import fal_client
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
|
|
|
| 6 |
import random
|
| 7 |
import requests
|
| 8 |
|
|
|
|
| 51 |
|
| 52 |
def process_image(img):
|
| 53 |
# First do the classification
|
| 54 |
+
predicted_class, idx, probs = learn.predict(img)
|
| 55 |
+
classification_results = dict(zip(learn.dls.vocab, map(float, probs)))
|
| 56 |
|
| 57 |
# Get Wikipedia URL for the predicted class
|
|
|
|
| 58 |
wiki_url = search_terms_wikipedia.get(predicted_class, "No Wikipedia entry found.")
|
| 59 |
|
| 60 |
# Generate FLUX image
|
|
|
|
| 62 |
"fal-ai/flux/schnell",
|
| 63 |
arguments={
|
| 64 |
"prompt": random.choice(prompt_templates).format(flower=predicted_class),
|
| 65 |
+
"image_size": "portrait_4_3"
|
| 66 |
},
|
| 67 |
with_logs=True,
|
| 68 |
on_queue_update=on_queue_update,
|
|
|
|
| 99 |
gr.Examples(
|
| 100 |
examples=examples,
|
| 101 |
inputs=input_image,
|
| 102 |
+
examples_per_page=6,
|
| 103 |
fn=process_image,
|
| 104 |
outputs=[label_output, generated_image, wiki_output]
|
| 105 |
)
|
download.webp
DELETED
|
Binary file (21.1 kB)
|
|
|