SHIKARICHACHA commited on
Commit
03b567f
·
verified ·
1 Parent(s): c03320e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -138,6 +138,31 @@ with gr.Blocks(title="OpenRouter AI Vision Interface", css="style.css") as demo:
138
  # Create examples directory if it doesn't exist
139
  os.makedirs("examples", exist_ok=True)
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  # For Hugging Face Spaces compatibility
142
  if __name__ == "__main__":
143
  # Launch the interface
 
138
  # Create examples directory if it doesn't exist
139
  os.makedirs("examples", exist_ok=True)
140
 
141
+ # Download example image if it doesn't exist
142
+ def download_example_image():
143
+ if not os.path.exists("examples/nature.jpg"):
144
+ import requests
145
+ from PIL import Image
146
+ from io import BytesIO
147
+
148
+ # URL of the example image
149
+ image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
150
+
151
+ # Download and save the image
152
+ response = requests.get(image_url)
153
+ if response.status_code == 200:
154
+ # Open the image from the response content
155
+ img = Image.open(BytesIO(response.content))
156
+
157
+ # Save the image to the examples directory
158
+ img.save("examples/nature.jpg")
159
+ print("Example image downloaded successfully!")
160
+ else:
161
+ print(f"Failed to download image. Status code: {response.status_code}")
162
+
163
+ # Download example image before launching the app
164
+ download_example_image()
165
+
166
  # For Hugging Face Spaces compatibility
167
  if __name__ == "__main__":
168
  # Launch the interface