Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import necessary libraries
|
2 |
+
import gradio as gr
|
3 |
+
import transformers_js_py
|
4 |
+
|
5 |
+
# Define the function to generate an image from text using the Liberata/illustrious-xl-v1.0 model
|
6 |
+
def generate_image(prompt, guidance_scale, num_inference_steps):
|
7 |
+
# Load the model from the specified file
|
8 |
+
model = transformers_js_py.StableDiffusionXLPipeline.from_pretrained(
|
9 |
+
"https://huggingface.co/Liberata/illustrious-xl-v1.0/resolve/main/Illustrious-XL-v1.0.safetensors"
|
10 |
+
)
|
11 |
+
# Generate the image from the text prompt with the specified parameters
|
12 |
+
image = model(prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
|
13 |
+
return image
|
14 |
+
|
15 |
+
# Create a Gradio interface for the text-to-image generation
|
16 |
+
with gr.Blocks() as demo:
|
17 |
+
# Create a textbox for the user to input the text prompt
|
18 |
+
prompt_input = gr.Textbox(label="Text Prompt")
|
19 |
+
# Create sliders for the guidance scale and number of inference steps
|
20 |
+
guidance_scale_slider = gr.Slider(1, 20, value=7.5, step=0.1, label="Guidance Scale")
|
21 |
+
num_inference_steps_slider = gr.Slider(1, 100, value=50, step=1, label="Number of Inference Steps")
|
22 |
+
# Create an image output to display the generated image
|
23 |
+
image_output = gr.Image(label="Generated Image")
|
24 |
+
# Create a button to trigger the image generation
|
25 |
+
generate_button = gr.Button("Generate Image")
|
26 |
+
|
27 |
+
# Add some documentation using HTML
|
28 |
+
gr.HTML("""
|
29 |
+
<h2>Text-to-Image Generation with Liberata/illustrious-xl-v1.0</h2>
|
30 |
+
<p>This app allows you to generate images from text prompts using the Liberata/illustrious-xl-v1.0 model.</p>
|
31 |
+
<p>Simply enter a text prompt, adjust the parameters, and click the 'Generate Image' button to see the generated image.</p>
|
32 |
+
""")
|
33 |
+
|
34 |
+
# Define the event listener for the button click
|
35 |
+
generate_button.click(fn=generate_image, inputs=[prompt_input, guidance_scale_slider, num_inference_steps_slider], outputs=image_output)
|
36 |
+
|
37 |
+
# Launch the Gradio app with share=True
|
38 |
+
if __name__ == "__main__":
|
39 |
+
demo.launch(share=True, show_error=True)
|