Delete app2.py
Browse files
app2.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
import os
|
| 4 |
-
from PIL import Image
|
| 5 |
-
import os
|
| 6 |
-
# Load environment variables
|
| 7 |
-
CHEVERETO_API_URL = os.environ.get("API_URL") # Your Chevereto API endpoint
|
| 8 |
-
CHEVERETO_API_KEY = os.environ.get("API_KEY") # Your Chevereto API Key
|
| 9 |
-
CHEVERETO_ALBUM_ID = os.environ.get("ALBUM_ID") # Your Album ID
|
| 10 |
-
|
| 11 |
-
# Load the Gradio model
|
| 12 |
-
model = gr.Interface.load("models/stabilityai/stable-diffusion-3.5-large")
|
| 13 |
-
|
| 14 |
-
def upload_to_chevereto(img_path: str) -> str:
|
| 15 |
-
"""Uploads an image to Chevereto and returns the public image URL."""
|
| 16 |
-
with open(img_path, "rb") as image_file:
|
| 17 |
-
files = {"source": image_file}
|
| 18 |
-
data = {
|
| 19 |
-
"key": CHEVERETO_API_KEY,
|
| 20 |
-
"format": "json",
|
| 21 |
-
"album": CHEVERETO_ALBUM_ID # Include the album ID
|
| 22 |
-
}
|
| 23 |
-
response = requests.post(CHEVERETO_API_URL, files=files, data=data)
|
| 24 |
-
|
| 25 |
-
if response.status_code == 200:
|
| 26 |
-
return response.json().get("image", {}).get("url") # Return the image URL
|
| 27 |
-
else:
|
| 28 |
-
return f"Error uploading image: {response.text}" # Debugging error message
|
| 29 |
-
|
| 30 |
-
def generate_image_and_upload(prompt: str) -> str:
|
| 31 |
-
"""Generates an image using the AI model and uploads it to Chevereto."""
|
| 32 |
-
img = model(prompt) # Generate image
|
| 33 |
-
|
| 34 |
-
if isinstance(img, list):
|
| 35 |
-
img = img[0] # If Gradio returns a list, get the first image
|
| 36 |
-
|
| 37 |
-
if isinstance(img, Image.Image):
|
| 38 |
-
img_path = "generated_image.png"
|
| 39 |
-
img.save(img_path, format="PNG") # Save locally before uploading
|
| 40 |
-
|
| 41 |
-
return upload_to_chevereto(img_path) # Upload and return URL
|
| 42 |
-
else:
|
| 43 |
-
return "Error: Model did not return a valid image"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
# Define Gradio API returning the Chevereto public URL
|
| 48 |
-
iface = gr.Interface(fn=generate_image_and_upload, inputs="text", outputs="text")
|
| 49 |
-
|
| 50 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|