Reduxxxx commited on
Commit
9180c95
·
verified ·
1 Parent(s): 70de8e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -2
app.py CHANGED
@@ -1,3 +1,59 @@
1
- # Load model directly
 
2
  from transformers import AutoModel
3
- model = AutoModel.from_pretrained("zxhezexin/openlrm-mix-large-1.1")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
  from transformers import AutoModel
4
+ import torch
5
+ import numpy as np
6
+ from PIL import Image
7
+
8
+ def load_model():
9
+ # 加载模型
10
+ model = AutoModel.from_pretrained("jadechoghari/vfusion3d", trust_remote_code=True)
11
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
+ model.to(device)
13
+ return model
14
+
15
+ def process_image(input_image):
16
+ try:
17
+ # 确保输入图像是PIL Image格式
18
+ if not isinstance(input_image, Image.Image):
19
+ input_image = Image.fromarray(input_image)
20
+
21
+ # 加载模型
22
+ model = load_model()
23
+
24
+ # 图像预处理
25
+ input_image = input_image.resize((256, 256))
26
+
27
+ # 转换为tensor
28
+ image_tensor = torch.from_numpy(np.array(input_image)).float()
29
+ image_tensor = image_tensor.permute(2, 0, 1).unsqueeze(0)
30
+
31
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
32
+ image_tensor = image_tensor.to(device)
33
+
34
+ # 模型推理
35
+ with torch.no_grad():
36
+ output = model(image_tensor)
37
+
38
+ return output
39
+
40
+ except Exception as e:
41
+ return f"错误: {str(e)}"
42
+
43
+ # 创建Gradio界面
44
+ demo = gr.Interface(
45
+ fn=process_image,
46
+ inputs=[
47
+ gr.Image(type="pil", label="上传图片")
48
+ ],
49
+ outputs=[
50
+ gr.Model3D(label="生成的3D模型"),
51
+ gr.Text(label="处理状态")
52
+ ],
53
+ title="麒迹云台 - 2D转3D模型生成器",
54
+ description="上传一张图片,AI将自动生成对应的3D模型。支持格式:jpg, png, jpeg",
55
+ theme=gr.themes.Soft()
56
+ )
57
+
58
+ if __name__ == "__main__":
59
+ demo.launch()