Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import fal_client
|
| 2 |
import gradio as gr
|
| 3 |
import io
|
|
@@ -8,6 +9,7 @@ import requests
|
|
| 8 |
from PIL import Image
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
from fastai.vision.all import *
|
|
|
|
| 11 |
from pathlib import Path
|
| 12 |
|
| 13 |
# Dictionary of plant names and their Wikipedia links
|
|
@@ -119,21 +121,18 @@ def process_image(img):
|
|
| 119 |
# Generate artistic interpretation using DALL-E
|
| 120 |
print("Sending request to DALL-E...")
|
| 121 |
try:
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
size="1024x1024",
|
| 126 |
-
|
| 127 |
-
|
| 128 |
)
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
print(f"Image URL: {image_url}")
|
| 133 |
-
|
| 134 |
-
# Download the generated image
|
| 135 |
-
response = requests.get(image_url)
|
| 136 |
-
generated_image = Image.open(io.BytesIO(response.content))
|
| 137 |
|
| 138 |
except Exception as e:
|
| 139 |
print(f"Error generating image: {e}")
|
|
|
|
| 1 |
+
import base64
|
| 2 |
import fal_client
|
| 3 |
import gradio as gr
|
| 4 |
import io
|
|
|
|
| 9 |
from PIL import Image
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from fastai.vision.all import *
|
| 12 |
+
from openai import OpenAI
|
| 13 |
from pathlib import Path
|
| 14 |
|
| 15 |
# Dictionary of plant names and their Wikipedia links
|
|
|
|
| 121 |
# Generate artistic interpretation using DALL-E
|
| 122 |
print("Sending request to DALL-E...")
|
| 123 |
try:
|
| 124 |
+
client = OpenAI()
|
| 125 |
+
|
| 126 |
+
result = client.images.generate(
|
| 127 |
+
model="gpt-image-1",
|
| 128 |
+
prompt="Draw a 2D pixel art style sprite sheet of a tabby gray cat",
|
| 129 |
size="1024x1024",
|
| 130 |
+
background="transparent",
|
| 131 |
+
quality="high",
|
| 132 |
)
|
| 133 |
|
| 134 |
+
image_base64 = result.json()["data"][0]["b64_json"]
|
| 135 |
+
generated_image = base64.b64decode(image_base64)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
except Exception as e:
|
| 138 |
print(f"Error generating image: {e}")
|