Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
|
|
|
|
4 |
import spaces
|
5 |
|
6 |
# Load the fine-tuned model
|
@@ -10,22 +11,37 @@ def load_model():
|
|
10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
11 |
return model, tokenizer
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
# Function to generate an image
|
16 |
@spaces.GPU
|
17 |
-
def generate_image(prompt):
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
# Gradio interface
|
23 |
iface = gr.Interface(
|
24 |
fn=generate_image,
|
25 |
-
inputs=
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
)
|
30 |
|
31 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import torch
|
3 |
+
from diffusers import FluxDiffusionPipeline
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
import spaces
|
6 |
|
7 |
# Load the fine-tuned model
|
|
|
11 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
12 |
return model, tokenizer
|
13 |
|
14 |
+
# Load the base Flux Dev model
|
15 |
+
model_id = "black-forest-labs/FLUX.1-dev"
|
16 |
+
pipeline = FluxDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
17 |
+
pipeline = pipeline.to("cuda")
|
18 |
+
|
19 |
+
# Download and load the LoRA weights
|
20 |
+
lora_model_path = hf_hub_download("MegaTronX/SuicideGirl-FLUX", "SuicideGirls.safetensors")
|
21 |
+
pipeline.load_lora_weights(lora_model_path)
|
22 |
|
|
|
23 |
@spaces.GPU
|
24 |
+
def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps):
|
25 |
+
image = pipeline(
|
26 |
+
prompt=prompt,
|
27 |
+
negative_prompt=negative_prompt,
|
28 |
+
guidance_scale=guidance_scale,
|
29 |
+
num_inference_steps=num_inference_steps
|
30 |
+
).images[0]
|
31 |
+
return image
|
32 |
|
33 |
+
# Create the Gradio interface
|
34 |
iface = gr.Interface(
|
35 |
fn=generate_image,
|
36 |
+
inputs=[
|
37 |
+
gr.Textbox(label="Prompt"),
|
38 |
+
gr.Textbox(label="Negative Prompt"),
|
39 |
+
gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale"),
|
40 |
+
gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Number of Inference Steps")
|
41 |
+
],
|
42 |
+
outputs=gr.Image(type="pil"),
|
43 |
+
title="Image Generation with Flux Dev LoRA",
|
44 |
+
description="Generate images using a Flux Dev model with a custom LoRA fine-tune."
|
45 |
)
|
46 |
|
47 |
iface.launch()
|