Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the fine-tuned model
|
6 |
+
def load_model():
|
7 |
+
model_name = "MegaTronX/SuicideGirl-FLUX" # Replace with your model path
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
+
return model, tokenizer
|
11 |
+
|
12 |
+
model, tokenizer = load_model()
|
13 |
+
|
14 |
+
# Function to generate an image
|
15 |
+
def generate_image(prompt):
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
17 |
+
outputs = model.generate(inputs["input_ids"], max_length=50)
|
18 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
19 |
+
|
20 |
+
# Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=generate_image,
|
23 |
+
inputs="text",
|
24 |
+
outputs="text",
|
25 |
+
title="Image Generation with LoRA Fine-Tuned Model",
|
26 |
+
description="Enter a prompt to generate an image using the fine-tuned model."
|
27 |
+
)
|
28 |
+
|
29 |
+
iface.launch()
|