kolibril13 commited on
Commit
4373daa
1 Parent(s): 17fc1f1

add new script

Browse files
Files changed (5) hide show
  1. .gitattributes +35 -0
  2. README.md +12 -0
  3. app.py +91 -0
  4. packages.txt +2 -0
  5. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Gradio Blender Bpy
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.43.2
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import bpy
3
+ from tqdm import tqdm
4
+ from math import pi
5
+ import tempfile
6
+ import molecularnodes as mn
7
+ import os
8
+
9
+
10
+ window = bpy.context.window
11
+ screen = window.screen
12
+
13
+ style = 'cartoon'
14
+
15
+ nodes_to_append = ["MN_color_set",
16
+ "MN_color_common",
17
+ "MN_color_attribute_random",
18
+ mn.nodes.styles_mapping[style]]
19
+
20
+ def get_areas(type):
21
+ return [area for area in screen.areas if area.type == type]
22
+
23
+ def get_regions(areas):
24
+ return [region for region in areas[0].regions if region.type == 'WINDOW']
25
+
26
+ for node in nodes_to_append:
27
+ bpy.ops.wm.append(
28
+ 'INVOKE_DEFAULT',
29
+ directory = os.path.join(mn.nodes.mn_data_file, 'NodeTree'),
30
+ filename = node,
31
+ link = False
32
+ )
33
+
34
+ def generate(progress=gr.Progress(track_tqdm=True)):
35
+ area_type = 'VIEW_3D'
36
+ areas = get_areas(area_type)
37
+ with bpy.context.temp_override(window=window, area=areas[0], region=get_regions(areas)[0], screen=screen):
38
+
39
+
40
+ for obj in bpy.context.scene.objects:
41
+ if obj.type == 'MESH':
42
+ bpy.data.objects.remove(obj, do_unlink=True)
43
+
44
+ molecule = mn.load.molecule_rcsb("7TYG", starting_style=style, center_molecule=True) # <- this line would causes the error 🐛
45
+ molecule.select_set(True)
46
+ bpy.context.view_layer.objects.active = molecule
47
+
48
+ bpy.ops.view3d.camera_to_view_selected()
49
+ camera = bpy.data.objects["Camera"]
50
+ camera.data.dof.use_dof = True
51
+ camera.data.dof.focus_distance = 5
52
+ camera.data.dof.aperture_fstop = 4
53
+ camera.data.angle = pi / 3
54
+ camera.data.type = "PERSP"
55
+
56
+ with tempfile.NamedTemporaryFile(suffix=".JPEG", delete=False) as f:
57
+ bpy.context.scene.render.resolution_y = 1000
58
+ bpy.context.scene.render.resolution_x = 1000
59
+ bpy.context.scene.render.image_settings.file_format = "JPEG"
60
+ bpy.context.scene.render.filepath = f.name
61
+
62
+ with tqdm() as pbar:
63
+
64
+ def elapsed(dummy):
65
+ pbar.update()
66
+
67
+ bpy.app.handlers.render_stats.append(elapsed)
68
+ bpy.context.scene.frame_set(1)
69
+ bpy.context.scene.frame_current = 1
70
+ bpy.ops.render.render(animation=False, write_still=True)
71
+
72
+ bpy.data.images["Render Result"].save_render(
73
+ filepath=bpy.context.scene.render.filepath
74
+ )
75
+ bpy.app.handlers.render_stats.clear()
76
+ return f.name
77
+
78
+ with gr.Blocks() as demo:
79
+ with gr.Row():
80
+ with gr.Column():
81
+ render_btn = gr.Button("Render")
82
+ with gr.Column(scale=3):
83
+ image = gr.Image(type="filepath")
84
+
85
+ render_btn.click(
86
+ generate,
87
+ outputs=[image],
88
+ )
89
+
90
+ demo.queue(concurrency_count=1)
91
+ demo.launch(debug=True, inline=True)
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ libegl1-mesa-dev
2
+ libgl1-mesa-dev
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ bpy
2
+ molecularnodes