Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,140 +149,4 @@ with gr.Blocks() as demo:
|
|
| 149 |
)
|
| 150 |
|
| 151 |
# Start the application
|
| 152 |
-
demo.launch(inline=False)
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
# from fastai.vision.all import *
|
| 158 |
-
# import gradio as gr
|
| 159 |
-
# import fal_client
|
| 160 |
-
# from PIL import Image
|
| 161 |
-
# import io
|
| 162 |
-
# import random
|
| 163 |
-
# import requests
|
| 164 |
-
# from pathlib import Path
|
| 165 |
-
# import os
|
| 166 |
-
|
| 167 |
-
# # Set FAL API key
|
| 168 |
-
# os.environ["FAL_KEY"] = "19df8993-16d5-4561-a2f9-4649eff073e8:4b8330590d437063b9825805957694c5"
|
| 169 |
-
|
| 170 |
-
# # Plant names and their Wikipedia links
|
| 171 |
-
# search_terms_wikipedia = {
|
| 172 |
-
# "blazing star": "https://en.wikipedia.org/wiki/Mentzelia",
|
| 173 |
-
# "bristlecone pine": "https://en.wikipedia.org/wiki/Pinus_longaeva",
|
| 174 |
-
# "california bluebell": "https://en.wikipedia.org/wiki/Phacelia_minor",
|
| 175 |
-
# "california buckeye": "https://en.wikipedia.org/wiki/Aesculus_californica",
|
| 176 |
-
# "california buckwheat": "https://en.wikipedia.org/wiki/Eriogonum_fasciculatum",
|
| 177 |
-
# "california fuchsia": "https://en.wikipedia.org/wiki/Epilobium_canum",
|
| 178 |
-
# "california checkerbloom": "https://en.wikipedia.org/wiki/Sidalcea_malviflora",
|
| 179 |
-
# "california lilac": "https://en.wikipedia.org/wiki/Ceanothus",
|
| 180 |
-
# "california poppy": "https://en.wikipedia.org/wiki/Eschscholzia_californica",
|
| 181 |
-
# "california sagebrush": "https://en.wikipedia.org/wiki/Artemisia_californica",
|
| 182 |
-
# "california wild grape": "https://en.wikipedia.org/wiki/Vitis_californica",
|
| 183 |
-
# "california wild rose": "https://en.wikipedia.org/wiki/Rosa_californica",
|
| 184 |
-
# "coyote mint": "https://en.wikipedia.org/wiki/Monardella",
|
| 185 |
-
# "elegant clarkia": "https://en.wikipedia.org/wiki/Clarkia_unguiculata",
|
| 186 |
-
# "baby blue eyes": "https://en.wikipedia.org/wiki/Nemophila_menziesii",
|
| 187 |
-
# "hummingbird sage": "https://en.wikipedia.org/wiki/Salvia_spathacea",
|
| 188 |
-
# "delphinium": "https://en.wikipedia.org/wiki/Delphinium",
|
| 189 |
-
# "matilija poppy": "https://en.wikipedia.org/wiki/Romneya_coulteri",
|
| 190 |
-
# "blue-eyed grass": "https://en.wikipedia.org/wiki/Sisyrinchium_bellum",
|
| 191 |
-
# "penstemon spectabilis": "https://en.wikipedia.org/wiki/Penstemon_spectabilis",
|
| 192 |
-
# "seaside daisy": "https://en.wikipedia.org/wiki/Erigeron_glaucus",
|
| 193 |
-
# "sticky monkeyflower": "https://en.wikipedia.org/wiki/Diplacus_aurantiacus",
|
| 194 |
-
# "tidy tips": "https://en.wikipedia.org/wiki/Layia_platyglossa",
|
| 195 |
-
# "wild cucumber": "https://en.wikipedia.org/wiki/Marah_(plant)",
|
| 196 |
-
# "douglas iris": "https://en.wikipedia.org/wiki/Iris_douglasiana",
|
| 197 |
-
# "goldfields coreopsis": "https://en.wikipedia.org/wiki/Coreopsis"
|
| 198 |
-
# }
|
| 199 |
-
|
| 200 |
-
# # Templates for AI image generation
|
| 201 |
-
# prompt_templates = [
|
| 202 |
-
# "A dreamy watercolor scene of a {flower} on a misty morning trail, with golden sunbeams filtering through towering redwoods, and a curious hummingbird hovering nearby.",
|
| 203 |
-
# "A loose, expressive watercolor sketch of a {flower} in a wild meadow, surrounded by dancing butterflies and morning dew drops sparkling like diamonds in the dawn light.",
|
| 204 |
-
# "An artist's nature journal page featuring a detailed {flower} study, with delicate ink lines and soft watercolor washes, complete with small sketches of bees and field notes in the margins.",
|
| 205 |
-
# "A vibrant plein air painting of a {flower} patch along a coastal hiking trail, with crashing waves and rugged cliffs in the background, painted in bold, energetic brushstrokes.",
|
| 206 |
-
# "A whimsical mixed-media scene of a {flower} garden at sunrise, combining loose watercolor washes with detailed botanical illustrations, featuring hidden wildlife and morning fog rolling through the valley."
|
| 207 |
-
# ]
|
| 208 |
-
|
| 209 |
-
# # Example images
|
| 210 |
-
# examples = [
|
| 211 |
-
# str(Path('examples/example_1.jpg')),
|
| 212 |
-
# str(Path('examples/example_2.jpg')),
|
| 213 |
-
# str(Path('examples/example_3.jpg')),
|
| 214 |
-
# str(Path('examples/example_4.jpg')),
|
| 215 |
-
# str(Path('examples/example_5.jpg'))
|
| 216 |
-
# ]
|
| 217 |
-
|
| 218 |
-
# # Handle AI generation progress updates
|
| 219 |
-
# def on_queue_update(update):
|
| 220 |
-
# if isinstance(update, fal_client.InProgress):
|
| 221 |
-
# for log in update.logs:
|
| 222 |
-
# print(log["message"])
|
| 223 |
-
|
| 224 |
-
# # Main processing function
|
| 225 |
-
# def process_image(img):
|
| 226 |
-
# predicted_class, _, _ = learn.predict(img)
|
| 227 |
-
# wiki_url = search_terms_wikipedia.get(predicted_class, "No Wikipedia entry found.")
|
| 228 |
-
|
| 229 |
-
# result = fal_client.subscribe(
|
| 230 |
-
# "fal-ai/flux/schnell",
|
| 231 |
-
# arguments={
|
| 232 |
-
# "prompt": random.choice(prompt_templates).format(flower=predicted_class),
|
| 233 |
-
# "image_size": "portrait_4_3"
|
| 234 |
-
# },
|
| 235 |
-
# with_logs=True,
|
| 236 |
-
# on_queue_update=on_queue_update,
|
| 237 |
-
# )
|
| 238 |
-
|
| 239 |
-
# image_url = result['images'][0]['url']
|
| 240 |
-
# response = requests.get(image_url)
|
| 241 |
-
# generated_image = Image.open(io.BytesIO(response.content))
|
| 242 |
-
|
| 243 |
-
# return predicted_class, generated_image, wiki_url
|
| 244 |
-
|
| 245 |
-
# # Clear all outputs
|
| 246 |
-
# def clear_outputs():
|
| 247 |
-
# return {
|
| 248 |
-
# label_output: None,
|
| 249 |
-
# generated_image: None,
|
| 250 |
-
# wiki_output: None
|
| 251 |
-
# }
|
| 252 |
-
|
| 253 |
-
# # Load the model
|
| 254 |
-
# learn = load_learner('plants.pkl')
|
| 255 |
-
|
| 256 |
-
# # Gradio interface
|
| 257 |
-
# with gr.Blocks() as demo:
|
| 258 |
-
# with gr.Row():
|
| 259 |
-
# input_image = gr.Image(height=230, width=230, label="Upload Image for Classification", type="pil")
|
| 260 |
-
|
| 261 |
-
# with gr.Row():
|
| 262 |
-
# with gr.Column():
|
| 263 |
-
# label_output = gr.Textbox(label="Predicted Plant Name", lines=1)
|
| 264 |
-
# wiki_output = gr.Textbox(label="Wikipedia Article Link", lines=1)
|
| 265 |
-
# generated_image = gr.Image(label="AI Generated Interpretation")
|
| 266 |
-
|
| 267 |
-
# gr.Examples(
|
| 268 |
-
# examples=examples,
|
| 269 |
-
# inputs=input_image,
|
| 270 |
-
# examples_per_page=6,
|
| 271 |
-
# fn=process_image,
|
| 272 |
-
# outputs=[label_output, generated_image, wiki_output]
|
| 273 |
-
# )
|
| 274 |
-
|
| 275 |
-
# input_image.change(
|
| 276 |
-
# fn=process_image,
|
| 277 |
-
# inputs=input_image,
|
| 278 |
-
# outputs=[label_output, generated_image, wiki_output]
|
| 279 |
-
# )
|
| 280 |
-
|
| 281 |
-
# input_image.clear(
|
| 282 |
-
# fn=clear_outputs,
|
| 283 |
-
# inputs=[],
|
| 284 |
-
# outputs=[label_output, generated_image, wiki_output]
|
| 285 |
-
# )
|
| 286 |
-
|
| 287 |
-
# # Launch the demo
|
| 288 |
-
# demo.launch(inline=False)
|
|
|
|
| 149 |
)
|
| 150 |
|
| 151 |
# Start the application
|
| 152 |
+
demo.launch(inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|