Phauglin commited on
Commit
da3ef81
·
verified ·
1 Parent(s): b6410a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -4,6 +4,8 @@ import fal_client
4
  from PIL import Image
5
  import io
6
  import base64
 
 
7
 
8
  search_terms_wikipedia = {
9
  "blazing star": "https://en.wikipedia.org/wiki/Mentzelia",
@@ -34,6 +36,15 @@ search_terms_wikipedia = {
34
  "goldfields coreopsis": "https://en.wikipedia.org/wiki/Coreopsis"
35
  }
36
 
 
 
 
 
 
 
 
 
 
37
  def on_queue_update(update):
38
  if isinstance(update, fal_client.InProgress):
39
  for log in update.logs:
@@ -52,16 +63,16 @@ def process_image(img):
52
  result = fal_client.subscribe(
53
  "fal-ai/flux/schnell",
54
  arguments={
55
- "prompt": f"A detailed, artistic interpretation of {predicted_class} flower in natural setting",
56
- "image_size": "square" # Changed from "256x256" to "square"
57
  },
58
  with_logs=True,
59
  on_queue_update=on_queue_update,
60
  )
61
 
62
- # Convert the image data
63
- image_data = base64.b64decode(result['image'])
64
- generated_image = Image.open(io.BytesIO(image_data))
65
 
66
  return classification_results, generated_image, wiki_url
67
 
@@ -81,17 +92,7 @@ with gr.Blocks() as demo:
81
  # Example images
82
  examples = [
83
  'https://www.deserthorizonnursery.com/wp-content/uploads/2024/03/Brittlebush-Encelia-Farinosa-desert-horizon-nursery.jpg',
84
- 'https://cdn.mos.cms.futurecdn.net/VJE7gSuQ9KWbkqEsWgX5zS.jpg',
85
- 'https://silverfallsseed.com/wp-content/uploads/2016/01/tidy-tips-_-9.jpg',
86
- 'https://cdn11.bigcommerce.com/s-1b9100svju/images/stencil/1280x1280/products/2044/1440/DETA-635__75522.1664817787.jpg?c=1',
87
- 'https://shop.stoverseed.com/cdn/shop/products/DesertBluebells_CaliforniaBluebells-_Phaceliacampanularia_closeup_530x@2x.jpg?v=1596506040',
88
- 'https://images.squarespace-cdn.com/content/v1/57488264f85082748c7c80db/d0e8480a-4eff-4219-88f8-e5ae6b32e81e/monkeyflower.jpg',
89
- 'https://www.parksconservancy.org/sites/default/files/styles/basic/public/A_GEN_131213_WTE_109.jpg?itok=9SDtr4b2',
90
- 'https://silverfallsseed.com/wp-content/uploads/2016/01/tidy-tips-_-9.jpg',
91
- 'https://vnps.org/wp-content/uploads/2021/05/Narrow-leaved-Blue-eyed-Grass-4-Sisyrinchium-angustifolium-by-Betsy-Washington.jpg',
92
- 'https://gardenerspath.com/wp-content/uploads/2022/02/How-to-Grow-Baby-Blue-Eyes-Feature.jpg',
93
- 'https://images.squarespace-cdn.com/content/v1/57488264f85082748c7c80db/d0e8480a-4eff-4219-88f8-e5ae6b32e81e/monkeyflower.jpg'
94
-
95
  ]
96
  gr.Examples(
97
  examples=examples,
 
4
  from PIL import Image
5
  import io
6
  import base64
7
+ import random
8
+ import requests
9
 
10
  search_terms_wikipedia = {
11
  "blazing star": "https://en.wikipedia.org/wiki/Mentzelia",
 
36
  "goldfields coreopsis": "https://en.wikipedia.org/wiki/Coreopsis"
37
  }
38
 
39
+ # Update prompt templates
40
+ prompt_templates = [
41
+ "A cosmic {flower} blooming in space, with petals made of swirling galaxies and nebulae, glowing softly against a backdrop of distant stars.",
42
+ "An enchanted garden filled with a bioluminescent {flower}, each petal radiating vibrant, otherworldly colors, illuminating the dark, mystical forest around them.",
43
+ "A mechanical {flower} with petals made of polished metal and intricate gears, unfolding in a steampunk-inspired futuristic landscape.",
44
+ "A surreal pot of a {flower} where each bloom is a miniature landscape, showing tiny mountains, rivers, and clouds nestled within the petals.",
45
+ "An abstract explosion of a {flower}, blending vibrant colors and fluid shapes in a chaotic, dreamlike composition, evoking movement and emotion."
46
+ ]
47
+
48
  def on_queue_update(update):
49
  if isinstance(update, fal_client.InProgress):
50
  for log in update.logs:
 
63
  result = fal_client.subscribe(
64
  "fal-ai/flux/schnell",
65
  arguments={
66
+ "prompt": random.choice(prompt_templates).format(flower=predicted_class),
67
+ "image_size": "square"
68
  },
69
  with_logs=True,
70
  on_queue_update=on_queue_update,
71
  )
72
 
73
+ image_url = result['images'][0]['url']
74
+ response = requests.get(image_url)
75
+ generated_image = Image.open(io.BytesIO(response.content))
76
 
77
  return classification_results, generated_image, wiki_url
78
 
 
92
  # Example images
93
  examples = [
94
  'https://www.deserthorizonnursery.com/wp-content/uploads/2024/03/Brittlebush-Encelia-Farinosa-desert-horizon-nursery.jpg',
95
+ 'https://cdn.mos.cms.futurecdn.net/VJE7gSuQ9KWbkqEsWgX5zS.jpg'
 
 
 
 
 
 
 
 
 
 
96
  ]
97
  gr.Examples(
98
  examples=examples,