kikopubisher commited on
Commit
619c5e1
·
verified ·
1 Parent(s): 96698ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -1,25 +1,24 @@
1
  import streamlit as st
2
  from PIL import Image
3
  import torch
4
- from transformers import pipeline
5
- import numpy as np
6
  import io
 
7
 
8
  # إعداد الصفحة
9
- st.set_page_config(page_title="Image to Video with Editing", page_icon="🎥")
10
 
11
  # عنوان الصفحة
12
- st.title("Stable Video Diffusion - Image to Video")
13
 
14
  # تعليمات
15
- st.write("Upload an image to generate a video. You can also adjust settings for video generation.")
16
 
17
  # تحميل النموذج
18
  @st.cache_resource
19
  def load_model():
20
- model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
21
- # تأكد من استخدام الكلاس الصحيح من مكتبة transformers إذا كان متاحًا
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 Video'):
38
- # تحويل الصورة إلى فيديو
39
- with st.spinner("Generating video..."):
40
- video_frames = pipe(image, num_frames=frame_count)
41
 
42
- st.success("Video generated successfully!")
 
 
 
 
43
 
44
- # عرض الفيديو
45
- st.video(video_frames[0], format="video/mp4")
 
 
 
46
 
47
- # تنزيل الفيديو
48
- video_bytes = io.BytesIO()
49
- video_frames[0].save(video_bytes, format="mp4")
50
- st.download_button(label="Download Video", data=video_bytes.getvalue(), file_name="generated_video.mp4", mime="video/mp4")
51
 
52
  # تقديم بعض المعلومات حول النموذج
53
  st.write("""
54
- ### About the Model:
55
- SVD Image-to-Video is a latent diffusion model trained to generate short video clips from an image conditioning.
56
- This model generates frames at a resolution of 576x1024 given a context frame of the same size, fine-tuned from the SVD Image-to-Video [14 frames] model.
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
+ """)