Update app.py
Browse files
app.py
CHANGED
|
@@ -13,17 +13,20 @@ import sympy as sp
|
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
import numpy as np
|
| 15 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
def
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
if response.status_code == 200:
|
| 24 |
-
return response.content
|
| 25 |
-
else:
|
| 26 |
-
return None
|
| 27 |
|
| 28 |
x = sp.symbols("x")
|
| 29 |
|
|
@@ -446,11 +449,12 @@ def create_chatbot():
|
|
| 446 |
""")
|
| 447 |
|
| 448 |
with gr.Tab("AI Image Generator"):
|
| 449 |
-
gr.Markdown("##
|
| 450 |
prompt = gr.Textbox(label="Enter a prompt")
|
| 451 |
-
|
| 452 |
output = gr.Image(type="pil")
|
| 453 |
-
|
|
|
|
| 454 |
|
| 455 |
gr.HTML("""
|
| 456 |
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
|
|
|
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
import numpy as np
|
| 15 |
from io import BytesIO
|
| 16 |
+
import gradio as gr
|
| 17 |
+
from diffusers import StableDiffusionPipeline
|
| 18 |
+
import torch
|
| 19 |
|
| 20 |
+
# Load model on CPU (no CUDA)
|
| 21 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 22 |
+
"CompVis/stable-diffusion-v1-4",
|
| 23 |
+
torch_dtype=torch.float32
|
| 24 |
+
)
|
| 25 |
+
pipe = pipe.to("cpu")
|
| 26 |
|
| 27 |
+
def generate(prompt):
|
| 28 |
+
image = pipe(prompt).images[0]
|
| 29 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
x = sp.symbols("x")
|
| 32 |
|
|
|
|
| 449 |
""")
|
| 450 |
|
| 451 |
with gr.Tab("AI Image Generator"):
|
| 452 |
+
gr.Markdown("## Free Stable Diffusion Image Generator (CPU)")
|
| 453 |
prompt = gr.Textbox(label="Enter a prompt")
|
| 454 |
+
generate_btn = gr.Button("Generate Image")
|
| 455 |
output = gr.Image(type="pil")
|
| 456 |
+
|
| 457 |
+
generate_btn.click(fn=generate, inputs=prompt, outputs=output)
|
| 458 |
|
| 459 |
gr.HTML("""
|
| 460 |
<link href="https://fonts.googleapis.com/css2?family=Anton&display=swap" rel="stylesheet">
|