Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
|
|
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
print("
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
torch_dtype=torch.bfloat16,
|
| 14 |
-
device_map="cpu"
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
def generate_ui(image):
|
| 18 |
if image is None:
|
| 19 |
return "Please upload a sketch image first."
|
|
@@ -41,7 +51,6 @@ def generate_ui(image):
|
|
| 41 |
|
| 42 |
return generated_code
|
| 43 |
|
| 44 |
-
# Gradio ka Interface jo frontend testing UI aur API dono banayega
|
| 45 |
iface = gr.Interface(
|
| 46 |
fn=generate_ui,
|
| 47 |
inputs=gr.Image(type="pil", label="Upload Sketch"),
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
|
| 3 |
+
from peft import PeftModel
|
| 4 |
import torch
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
+
# 1. Aapka apna model (Jisme naya knowledge hai)
|
| 8 |
+
adapter_id = "ocilab/flowdex-sketch-model"
|
| 9 |
+
# 2. Original Base Model (Jiske upar knowledge attach hoga)
|
| 10 |
+
base_model_id = "unsloth/Qwen2-VL-2B-Instruct"
|
| 11 |
|
| 12 |
+
print("AI Pipeline Setup ho rahi hai... (Takes a moment on CPU)")
|
| 13 |
+
|
| 14 |
+
# Processor aapke adapter se hi load hoga
|
| 15 |
+
processor = AutoProcessor.from_pretrained(adapter_id)
|
| 16 |
+
|
| 17 |
+
# Pehle Base Model load karein
|
| 18 |
+
base_model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 19 |
+
base_model_id,
|
| 20 |
torch_dtype=torch.bfloat16,
|
| 21 |
+
device_map="cpu"
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# Ab base model ke upar aapki training attach karein
|
| 25 |
+
model = PeftModel.from_pretrained(base_model, adapter_id)
|
| 26 |
+
|
| 27 |
def generate_ui(image):
|
| 28 |
if image is None:
|
| 29 |
return "Please upload a sketch image first."
|
|
|
|
| 51 |
|
| 52 |
return generated_code
|
| 53 |
|
|
|
|
| 54 |
iface = gr.Interface(
|
| 55 |
fn=generate_ui,
|
| 56 |
inputs=gr.Image(type="pil", label="Upload Sketch"),
|