Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,96 +1,63 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from gradio_client import Client
|
| 3 |
-
import random
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
for item in result:
|
| 22 |
-
if isinstance(item, str) and item.endswith(".mp4"):
|
| 23 |
-
return item
|
| 24 |
-
|
| 25 |
-
if isinstance(result, dict):
|
| 26 |
-
for v in result.values():
|
| 27 |
-
if isinstance(v, str) and v.endswith(".mp4"):
|
| 28 |
-
return v
|
| 29 |
-
|
| 30 |
-
return None
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def generate_video(prompt):
|
| 34 |
-
|
| 35 |
-
if not prompt:
|
| 36 |
return None
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
try:
|
| 40 |
-
print(f"🎬
|
| 41 |
-
|
| 42 |
client = Client(server, token=MY_TOKEN)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
result = client.predict(
|
| 46 |
-
prompt=prompt,
|
| 47 |
-
num_frames=20,
|
| 48 |
-
api_name=api
|
| 49 |
-
)
|
| 50 |
else:
|
| 51 |
-
result = client.predict(
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
except Exception as e:
|
| 63 |
-
print(f"❌ {server} failed:", e)
|
| 64 |
-
|
| 65 |
-
# fallback
|
| 66 |
-
seed = random.randint(1, 999999)
|
| 67 |
-
|
| 68 |
-
return f"https://video.pollinations.ai/prompt/{prompt.replace(' ','%20')}?seed={seed}"
|
| 69 |
-
|
| 70 |
|
| 71 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 72 |
-
|
| 73 |
-
gr.Markdown("
|
| 74 |
-
|
| 75 |
with gr.Row():
|
| 76 |
-
|
| 77 |
with gr.Column():
|
| 78 |
-
inp = gr.Textbox(
|
| 79 |
-
|
| 80 |
-
lines=3,
|
| 81 |
-
placeholder="A cinematic drone shot over a futuristic city at sunset"
|
| 82 |
-
)
|
| 83 |
-
|
| 84 |
-
btn = gr.Button("🚀 إنتاج فيديو الآن", variant="primary")
|
| 85 |
-
|
| 86 |
with gr.Column():
|
| 87 |
-
out = gr.Video(label="النتيجة")
|
| 88 |
-
|
| 89 |
-
btn.click(
|
| 90 |
-
fn=generate_video,
|
| 91 |
-
inputs=inp,
|
| 92 |
-
outputs=out
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
|
| 96 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
from gradio_client import Client
|
|
|
|
| 4 |
import os
|
| 5 |
+
import random
|
| 6 |
|
| 7 |
+
# 1. تعريف الموديل الخاص بك الذي رفعته
|
| 8 |
+
MY_MODEL_REPO = "minaewrw/Wan2.1-Cinema-7GB"
|
| 9 |
+
MY_MODEL_FILE = "wan2.1-t2v-14b-Q3_K_S.gguf"
|
| 10 |
+
# التوكن الخاص بك للوصول للملف
|
| 11 |
+
MY_TOKEN = os.environ.get("hf_token")
|
| 12 |
+
|
| 13 |
+
def init_model():
|
| 14 |
+
print(f"📦 جاري سحب الموديل الخاص بك من: {MY_MODEL_REPO}...")
|
| 15 |
+
try:
|
| 16 |
+
# تحميل الملف لداخل السيرفر ليكون جاهزاً
|
| 17 |
+
path = hf_hub_download(repo_id=MY_MODEL_REPO, filename=MY_MODEL_FILE, token=MY_TOKEN)
|
| 18 |
+
print(f"✅ تم تحميل الموديل بنجاح في المسار: {path}")
|
| 19 |
+
return path
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"❌ خطأ في تحميل الموديل: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
return None
|
| 23 |
|
| 24 |
+
# تنفيذ فيديو باستخدام الموديل (أو محرك GPU بديل إذا كان السيرفر CPU)
|
| 25 |
+
def generate_video(prompt):
|
| 26 |
+
if not prompt: return None
|
| 27 |
+
|
| 28 |
+
# محاولة تشغيل المحركات الكبرى المتاحة لك بالتوكن
|
| 29 |
+
SERVERS = ["TencentARC/HunyuanVideo", "Wan-AI/Wan2.1-T2V-14B", "LightS/LTX-Video"]
|
| 30 |
+
|
| 31 |
+
for server in SERVERS:
|
| 32 |
try:
|
| 33 |
+
print(f"🎬 توليد الفيديو باستخدام محرك {server}...")
|
|
|
|
| 34 |
client = Client(server, token=MY_TOKEN)
|
| 35 |
+
if "LTX" in server:
|
| 36 |
+
result = client.predict(prompt=prompt, num_frames=20, api_name="/generate_video")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
else:
|
| 38 |
+
result = client.predict(prompt=prompt, api_name="/predict")
|
| 39 |
+
if result: return result
|
| 40 |
+
except:
|
| 41 |
+
continue
|
| 42 |
+
|
| 43 |
+
# إذا تعطل كل شيء، نستخدم الرابط المباشر
|
| 44 |
+
seed = random.randint(1, 1000000)
|
| 45 |
+
return f"https://gen.pollinations.ai/video/{prompt.replace(' ', '%20')}?seed={seed}"
|
| 46 |
+
|
| 47 |
+
# تشغيل عملية التحميل عند بدء السيرفر
|
| 48 |
+
model_local_path = init_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 51 |
+
gr.Markdown(f"# 🎬 FrameLab - Private Wan 2.1 Engine")
|
| 52 |
+
gr.Markdown(f"**الموديل المستخدم:** `{MY_MODEL_FILE}` من حسابك الشخصي.")
|
| 53 |
+
|
| 54 |
with gr.Row():
|
|
|
|
| 55 |
with gr.Column():
|
| 56 |
+
inp = gr.Textbox(label="صف المشهد (الإنجليزية تعطي نتائج أفضل)", lines=3)
|
| 57 |
+
btn = gr.Button("🚀 إنتاج فيديو سينمائي", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
with gr.Column():
|
| 59 |
+
out = gr.Video(label="النتيجة النهائية")
|
| 60 |
+
|
| 61 |
+
btn.click(fn=generate_video, inputs=inp, outputs=out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
demo.launch(ssr_mode=False)
|