abdelrahman98 commited on
Commit
4cace2e
·
verified ·
1 Parent(s): f54f367

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load the smaller StarVector model (lighter, runs fine on free Hugging Face hardware)
7
+ model_id = "starvector/starvector-1b-im2svg"
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
10
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16)
11
+
12
+ def convert_to_svg(image):
13
+ # Prepare the image and run inference
14
+ inputs = tokenizer(image, return_tensors="pt")
15
+ outputs = model.generate(**inputs, max_new_tokens=1024)
16
+ svg_code = tokenizer.decode(outputs[0])
17
+ return svg_code
18
+
19
+ demo = gr.Interface(
20
+ fn=convert_to_svg,
21
+ inputs=gr.Image(type="pil", label="Upload Image"),
22
+ outputs=gr.Code(language="svg", label="Generated SVG Code"),
23
+ title="StarVector Image → SVG Converter"
24
+ )
25
+
26
+ demo.launch()