Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,26 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import base64
|
3 |
+
from io import BytesIO
|
4 |
+
from PIL import Image
|
5 |
|
6 |
+
# Function to convert image to base64
|
7 |
+
def image_to_base64(image: Image.Image):
|
8 |
+
buffered = BytesIO()
|
9 |
+
image.save(buffered, format="PNG") # You can change the format if needed
|
10 |
+
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
11 |
+
|
12 |
+
# Function to generate the image and return base64-encoded response
|
13 |
+
def generate_base64_image(prompt: str):
|
14 |
+
# Load the pre-trained model (adjust to your needs)
|
15 |
+
model = gr.load("models/stabilityai/stable-diffusion-3.5-large")
|
16 |
+
|
17 |
+
# Generate image with the model
|
18 |
+
img = model.predict(prompt)[0] # Assuming the model returns the generated image
|
19 |
+
|
20 |
+
# Convert image to base64
|
21 |
+
return image_to_base64(img)
|
22 |
+
|
23 |
+
# Define Gradio interface
|
24 |
+
iface = gr.Interface(fn=generate_base64_image, inputs="text", outputs="text") # Outputs base64 text
|
25 |
+
|
26 |
+
iface.launch()
|