Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ GITHUB_REPO = os.environ.get("GITHUB_REPO", "vid-test")
|
|
| 14 |
SPACE_HOST = os.environ.get("SPACE_HOST", "")
|
| 15 |
SPACE_URL = f"https://{SPACE_HOST}"
|
| 16 |
|
|
|
|
| 17 |
def delete_github_run(gh_run_id):
|
| 18 |
time.sleep(15)
|
| 19 |
url = f"https://api.github.com/repos/{GITHUB_USER}/{GITHUB_REPO}/actions/runs/{gh_run_id}"
|
|
@@ -23,12 +24,16 @@ def delete_github_run(gh_run_id):
|
|
| 23 |
|
| 24 |
@app.route('/')
|
| 25 |
def index():
|
|
|
|
| 26 |
return render_template('fluxpro.html')
|
| 27 |
|
| 28 |
@app.route('/<page_name>')
|
| 29 |
def serve_html(page_name):
|
|
|
|
| 30 |
try:
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
except:
|
| 33 |
return "Page not found", 404
|
| 34 |
|
|
@@ -45,17 +50,23 @@ def generate():
|
|
| 45 |
|
| 46 |
english_prompt = persian_prompt
|
| 47 |
|
| 48 |
-
#
|
| 49 |
try:
|
| 50 |
print(f"Translating: {persian_prompt}")
|
| 51 |
translator = Client("hamed744/translate-tts-aloha")
|
| 52 |
-
|
|
|
|
| 53 |
result = translator.predict(
|
| 54 |
-
persian_prompt,
|
| 55 |
-
"انگلیسی (آمریکا) - جنی (زن)",
|
| 56 |
-
0,
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
)
|
|
|
|
|
|
|
|
|
|
| 59 |
if isinstance(result, (list, tuple)) and len(result) > 0:
|
| 60 |
english_prompt = result[0]
|
| 61 |
elif isinstance(result, str):
|
|
@@ -64,9 +75,9 @@ def generate():
|
|
| 64 |
print(f"Translated to: {english_prompt}")
|
| 65 |
except Exception as e:
|
| 66 |
print("Translation error:", e)
|
| 67 |
-
#
|
| 68 |
|
| 69 |
-
#
|
| 70 |
run_id = str(uuid.uuid4())
|
| 71 |
url = f"https://api.github.com/repos/{GITHUB_USER}/{GITHUB_REPO}/dispatches"
|
| 72 |
headers = {
|
|
@@ -101,6 +112,7 @@ def webhook_upload():
|
|
| 101 |
file = request.files['file']
|
| 102 |
file.save(f"static/images/{run_id}.webp")
|
| 103 |
|
|
|
|
| 104 |
if gh_run_id:
|
| 105 |
threading.Thread(target=delete_github_run, args=(gh_run_id,)).start()
|
| 106 |
|
|
|
|
| 14 |
SPACE_HOST = os.environ.get("SPACE_HOST", "")
|
| 15 |
SPACE_URL = f"https://{SPACE_HOST}"
|
| 16 |
|
| 17 |
+
# تابع پاک کردن لاگ از گیتهاب
|
| 18 |
def delete_github_run(gh_run_id):
|
| 19 |
time.sleep(15)
|
| 20 |
url = f"https://api.github.com/repos/{GITHUB_USER}/{GITHUB_REPO}/actions/runs/{gh_run_id}"
|
|
|
|
| 24 |
|
| 25 |
@app.route('/')
|
| 26 |
def index():
|
| 27 |
+
# باز کردن صفحه پیشفرض
|
| 28 |
return render_template('fluxpro.html')
|
| 29 |
|
| 30 |
@app.route('/<page_name>')
|
| 31 |
def serve_html(page_name):
|
| 32 |
+
# قابلیت باز کردن هر صفحه اچتیامال (مثلاً site.com/fluxpro یا site.com/video)
|
| 33 |
try:
|
| 34 |
+
if not page_name.endswith('.html'):
|
| 35 |
+
page_name += '.html'
|
| 36 |
+
return render_template(page_name)
|
| 37 |
except:
|
| 38 |
return "Page not found", 404
|
| 39 |
|
|
|
|
| 50 |
|
| 51 |
english_prompt = persian_prompt
|
| 52 |
|
| 53 |
+
# --- ترجمه هوشمند با اتصال به اسپیس شما ---
|
| 54 |
try:
|
| 55 |
print(f"Translating: {persian_prompt}")
|
| 56 |
translator = Client("hamed744/translate-tts-aloha")
|
| 57 |
+
|
| 58 |
+
# ارسال ۵ پارامتر دقیقاً مطابق با اسپیس ترجمه شما
|
| 59 |
result = translator.predict(
|
| 60 |
+
persian_text=persian_prompt,
|
| 61 |
+
english_tts_voice_key="انگلیسی (آمریکا) - جنی (زن)",
|
| 62 |
+
rate=0,
|
| 63 |
+
volume=0,
|
| 64 |
+
pitch=0,
|
| 65 |
+
api_name="/predict"
|
| 66 |
)
|
| 67 |
+
|
| 68 |
+
# اسپیس شما یک Tuple برمیگرداند: (متن ترجمه شده, آدرس فایل صوتی)
|
| 69 |
+
# ما فقط متن (ایندکس 0) را میخواهیم
|
| 70 |
if isinstance(result, (list, tuple)) and len(result) > 0:
|
| 71 |
english_prompt = result[0]
|
| 72 |
elif isinstance(result, str):
|
|
|
|
| 75 |
print(f"Translated to: {english_prompt}")
|
| 76 |
except Exception as e:
|
| 77 |
print("Translation error:", e)
|
| 78 |
+
# اگر مترجم قطع بود، همان متن فارسی را استفاده کن
|
| 79 |
|
| 80 |
+
# --- ارسال دستور به گیتهاب اکشن ---
|
| 81 |
run_id = str(uuid.uuid4())
|
| 82 |
url = f"https://api.github.com/repos/{GITHUB_USER}/{GITHUB_REPO}/dispatches"
|
| 83 |
headers = {
|
|
|
|
| 112 |
file = request.files['file']
|
| 113 |
file.save(f"static/images/{run_id}.webp")
|
| 114 |
|
| 115 |
+
# روشن کردن تایمر برای پاک کردن اکشن گیتهاب
|
| 116 |
if gh_run_id:
|
| 117 |
threading.Thread(target=delete_github_run, args=(gh_run_id,)).start()
|
| 118 |
|