Text-to-Image / app.py
Dannyar608's picture
Update app.py
42d6a19 verified
raw
history blame
984 Bytes
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
import os
token = os.getenv('token')
from huggingface_hub import login
login(token=token)
gr.load("models/black-forest-labs/FLUX.1-dev").launch()
# Load the model (you can replace this with the specific Kwai-Kolors/Kolors model if available)
pipe = StableDiffusionPipeline.from_pretrained("Kwai-Kolors/Kolors")
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
# Define function to generate image from text
def generate_image(prompt):
# Generate an image based on the provided text prompt
image = pipe(prompt).images[0]
return image
# Create Gradio interface for chatbot
interface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="Enter your prompt:"),
outputs=gr.Image(type="pil"),
live=True,
title="Text-to-Image Generation",
description="Enter a text prompt to generate a photorealistic image."
)
# Launch the interface
interface.launch()