FarelDeveloper commited on
Commit
91ab284
·
verified ·
1 Parent(s): 19610b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import torch
3
+ from transformers import AutoModel, AutoProcessor
4
+
5
+ # Load di module level — ZeroGPU pakai CUDA emulation di luar @spaces.GPU
6
+ processor = AutoProcessor.from_pretrained("TaichuAI/ZDTaichu5.0-9B", trust_remote_code=True)
7
+ model = AutoModel.from_pretrained(
8
+ "TaichuAI/ZDTaichu5.0-9B",
9
+ torch_dtype=torch.bfloat16,
10
+ device_map="cuda", # bukan "auto", ZeroGPU butuh explicit cuda
11
+ trust_remote_code=True,
12
+ attn_implementation="sdpa",
13
+ ).eval()
14
+
15
+ @spaces.GPU(duration=60) # default 60s, bisa naik ke 120s
16
+ def generate(image, text):
17
+ messages = [{"role": "user", "content": [
18
+ {"type": "image", "image": image},
19
+ {"type": "text", "text": text},
20
+ ]}]
21
+ inputs = processor.from_messages(messages, return_tensors="pt").to("cuda")
22
+ with torch.inference_mode():
23
+ out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
24
+ return processor.decode(out[0], skip_special_tokens=True)
25
+
26
+ import gradio as gr
27
+ gr.Interface(fn=generate, inputs=[gr.Image(), gr.Text()], outputs="text").launch()