Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,6 @@ search_terms_wikipedia = {
|
|
| 37 |
"goldfields coreopsis": "https://en.wikipedia.org/wiki/Coreopsis"
|
| 38 |
}
|
| 39 |
|
| 40 |
-
|
| 41 |
flowers_endangerment = {
|
| 42 |
"Blazing Star": "Not considered endangered.",
|
| 43 |
"Bristlecone Pine": "Least Concern (stable population).",
|
|
@@ -109,8 +108,10 @@ def get_status(flower_name):
|
|
| 109 |
|
| 110 |
# Main function to process the uploaded image
|
| 111 |
def process_image(img):
|
| 112 |
-
|
| 113 |
predicted_class, _, probs = learn.predict(img)
|
|
|
|
|
|
|
| 114 |
classification_results = dict(zip(learn.dls.vocab, map(float, probs)))
|
| 115 |
|
| 116 |
# Get Wikipedia link
|
|
@@ -118,8 +119,10 @@ def process_image(img):
|
|
| 118 |
|
| 119 |
# Get endangerment status
|
| 120 |
endangerment_status = get_status(predicted_class)
|
| 121 |
-
|
|
|
|
| 122 |
# Generate artistic interpretation
|
|
|
|
| 123 |
result = fal_client.subscribe(
|
| 124 |
"fal-ai/flux/schnell",
|
| 125 |
arguments={
|
|
@@ -129,15 +132,19 @@ def process_image(img):
|
|
| 129 |
with_logs=True,
|
| 130 |
on_queue_update=on_queue_update,
|
| 131 |
)
|
| 132 |
-
|
|
|
|
| 133 |
# Retrieve image
|
| 134 |
image_url = result['images'][0]['url']
|
|
|
|
| 135 |
response = requests.get(image_url)
|
| 136 |
generated_image = Image.open(io.BytesIO(response.content))
|
| 137 |
|
|
|
|
| 138 |
return classification_results, generated_image, wiki_url, endangerment_status
|
| 139 |
|
| 140 |
|
|
|
|
| 141 |
# Function to clear all outputs
|
| 142 |
def clear_outputs():
|
| 143 |
return {
|
|
|
|
| 37 |
"goldfields coreopsis": "https://en.wikipedia.org/wiki/Coreopsis"
|
| 38 |
}
|
| 39 |
|
|
|
|
| 40 |
flowers_endangerment = {
|
| 41 |
"Blazing Star": "Not considered endangered.",
|
| 42 |
"Bristlecone Pine": "Least Concern (stable population).",
|
|
|
|
| 108 |
|
| 109 |
# Main function to process the uploaded image
|
| 110 |
def process_image(img):
|
| 111 |
+
print("Starting prediction...")
|
| 112 |
predicted_class, _, probs = learn.predict(img)
|
| 113 |
+
print(f"Prediction complete: {predicted_class}")
|
| 114 |
+
|
| 115 |
classification_results = dict(zip(learn.dls.vocab, map(float, probs)))
|
| 116 |
|
| 117 |
# Get Wikipedia link
|
|
|
|
| 119 |
|
| 120 |
# Get endangerment status
|
| 121 |
endangerment_status = get_status(predicted_class)
|
| 122 |
+
print(f"Status found: {endangerment_status}")
|
| 123 |
+
|
| 124 |
# Generate artistic interpretation
|
| 125 |
+
print("Sending request to FAL API...")
|
| 126 |
result = fal_client.subscribe(
|
| 127 |
"fal-ai/flux/schnell",
|
| 128 |
arguments={
|
|
|
|
| 132 |
with_logs=True,
|
| 133 |
on_queue_update=on_queue_update,
|
| 134 |
)
|
| 135 |
+
print("FAL API responded")
|
| 136 |
+
|
| 137 |
# Retrieve image
|
| 138 |
image_url = result['images'][0]['url']
|
| 139 |
+
print(f"Image URL: {image_url}")
|
| 140 |
response = requests.get(image_url)
|
| 141 |
generated_image = Image.open(io.BytesIO(response.content))
|
| 142 |
|
| 143 |
+
print("Image retrieved and ready to return")
|
| 144 |
return classification_results, generated_image, wiki_url, endangerment_status
|
| 145 |
|
| 146 |
|
| 147 |
+
|
| 148 |
# Function to clear all outputs
|
| 149 |
def clear_outputs():
|
| 150 |
return {
|