Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
-
from
|
5 |
-
import numpy as np
|
6 |
import io
|
|
|
7 |
|
8 |
# إعداد الصفحة
|
9 |
-
st.set_page_config(page_title="
|
10 |
|
11 |
# عنوان الصفحة
|
12 |
-
st.title("
|
13 |
|
14 |
# تعليمات
|
15 |
-
st.write("Upload an image to generate a
|
16 |
|
17 |
# تحميل النموذج
|
18 |
@st.cache_resource
|
19 |
def load_model():
|
20 |
-
model_id = "
|
21 |
-
|
22 |
-
pipe = pipeline("image-to-video", model=model_id, torch_dtype=torch.float16).to("cuda")
|
23 |
return pipe
|
24 |
|
25 |
pipe = load_model()
|
@@ -27,32 +26,33 @@ pipe = load_model()
|
|
27 |
# إدخال المستخدم
|
28 |
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
29 |
|
30 |
-
# إعداد الخيارات لتعديل الفيديو
|
31 |
-
frame_count = st.slider("Number of frames", min_value=10, max_value=50, value=25, step=5)
|
32 |
-
|
33 |
if uploaded_image is not None:
|
34 |
-
image = Image.open(uploaded_image)
|
35 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
36 |
|
37 |
-
if st.button('Generate
|
38 |
-
# تحويل الصورة إلى
|
39 |
-
|
40 |
-
video_frames = pipe(image, num_frames=frame_count)
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
# عرض
|
45 |
-
st.
|
|
|
|
|
|
|
46 |
|
47 |
-
# تنزيل
|
48 |
-
|
49 |
-
|
50 |
-
st.download_button(label="Download
|
51 |
|
52 |
# تقديم بعض المعلومات حول النموذج
|
53 |
st.write("""
|
54 |
-
### About
|
55 |
-
|
56 |
-
|
57 |
-
The widely used f8-decoder is also fine-tuned for temporal consistency, making the output videos more stable and coherent.
|
58 |
-
""")
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
+
from diffusers import DiffusionPipeline
|
|
|
5 |
import io
|
6 |
+
import numpy as np
|
7 |
|
8 |
# إعداد الصفحة
|
9 |
+
st.set_page_config(page_title="InstantMesh - 3D Mesh Generation", page_icon="🖼️")
|
10 |
|
11 |
# عنوان الصفحة
|
12 |
+
st.title("InstantMesh - 3D Mesh Generation from Image")
|
13 |
|
14 |
# تعليمات
|
15 |
+
st.write("Upload an image to generate a 3D mesh. InstantMesh creates detailed 3D models within seconds.")
|
16 |
|
17 |
# تحميل النموذج
|
18 |
@st.cache_resource
|
19 |
def load_model():
|
20 |
+
model_id = "TencentARC/InstantMesh"
|
21 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
|
|
|
22 |
return pipe
|
23 |
|
24 |
pipe = load_model()
|
|
|
26 |
# إدخال المستخدم
|
27 |
uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
28 |
|
|
|
|
|
|
|
29 |
if uploaded_image is not None:
|
30 |
+
image = Image.open(uploaded_image).convert("RGB")
|
31 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
32 |
|
33 |
+
if st.button('Generate 3D Mesh'):
|
34 |
+
# تحويل الصورة إلى تنسور
|
35 |
+
image_tensor = torch.tensor(np.array(image)).float().unsqueeze(0).permute(0, 3, 1, 2).to("cuda") / 255.0
|
|
|
36 |
|
37 |
+
# توليد الشبكة ثلاثية الأبعاد
|
38 |
+
with st.spinner("Generating 3D mesh..."):
|
39 |
+
mesh = pipe(image_tensor).images
|
40 |
+
|
41 |
+
st.success("3D mesh generated successfully!")
|
42 |
|
43 |
+
# عرض النتيجة
|
44 |
+
st.write("### 3D Mesh Preview")
|
45 |
+
# حاوية لعرض الـ 3D Mesh
|
46 |
+
# ملاحظة: قد تحتاج إلى تكوين طريقة لعرض أو تحميل النموذج ثلاثي الأبعاد بشكل صحيح.
|
47 |
+
st.image(mesh[0], caption="Generated 3D Mesh", use_column_width=True)
|
48 |
|
49 |
+
# تنزيل النموذج
|
50 |
+
mesh_bytes = io.BytesIO()
|
51 |
+
mesh[0].save(mesh_bytes, format="png") # استخدم الصيغة المناسبة هنا
|
52 |
+
st.download_button(label="Download 3D Mesh", data=mesh_bytes.getvalue(), file_name="generated_mesh.png", mime="image/png")
|
53 |
|
54 |
# تقديم بعض المعلومات حول النموذج
|
55 |
st.write("""
|
56 |
+
### About InstantMesh:
|
57 |
+
InstantMesh is a feed-forward framework for instant 3D mesh generation from a single image. It uses a combination of a multiview diffusion model and a sparse-view reconstruction model based on the LRM architecture to create diverse 3D assets quickly. The framework integrates a differentiable iso-surface extraction module to optimize the mesh representation, making it highly efficient and accurate.
|
58 |
+
""")
|
|
|
|