brightpay commited on
Commit
7d0642a
Β·
verified Β·
1 Parent(s): 955605c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -1,25 +1,31 @@
1
- import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- from PIL import Image
4
- import numpy as np
 
 
 
 
 
 
 
5
 
6
- # Load the model
7
- model_name = "maria26/Floor_Plan_LoRA"
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
- model = AutoModelForCausalLM.from_pretrained(model_name)
10
- model.eval()
11
 
12
- def predict(input_data):
13
- # Tokenize input
14
- inputs = tokenizer(input_data, return_tensors="pt")
15
 
16
- # Generate output
17
- outputs = model.generate(inputs["input_ids"], max_length=50)
18
 
19
- # Postprocess the output (replace with actual model output)
20
- image_array = np.random.rand(128, 128, 3) * 255 # Placeholder for image
21
- return Image.fromarray(image_array.astype("uint8"))
 
 
 
 
22
 
23
- # Define Gradio interface
24
  interface = gr.Interface(fn=predict, inputs="text", outputs="image")
25
- interface.launch()
 
1
+ from diffusers import StableDiffusionPipeline
2
+ from safetensors.torch import load_file
3
+ import torch
4
+
5
+ def load_pipeline(base_model_path, lora_path):
6
+ # Load base SD-v1.5 pipeline
7
+ pipeline = StableDiffusionPipeline.from_pretrained(base_model_path)
8
+
9
+ # Load LoRA weights
10
+ lora_state_dict = load_file(lora_path)
11
+ pipeline.unet.load_attn_procs(lora_state_dict)
12
 
13
+ return pipeline
 
 
 
 
14
 
15
+ # Paths to the base model and LoRA weights
16
+ base_model_path = "path/to/sd-v1-5"
17
+ lora_path = "path/to/Floor_Plan_LoRA.safetensors"
18
 
19
+ # Load the pipeline
20
+ pipeline = load_pipeline(base_model_path, lora_path)
21
 
22
+ def predict(prompt):
23
+ # Generate an image based on the prompt
24
+ result = pipeline(prompt).images[0]
25
+ return result
26
+
27
+ # Create Gradio Interface
28
+ import gradio as gr
29
 
 
30
  interface = gr.Interface(fn=predict, inputs="text", outputs="image")
31
+ interface.launch()