PCoreX / app.py
MageLord's picture
Create app.py
85674f0 verified
Raw
History Blame Contribute Delete
3.29 kB
import os
import json
import requests
import gradio as ui
# 🔒 ŞİFRELERİ ARTIK HF KASASINDAN GÜVENLİCE ÇEKİYORUZ (Tarayıcıya takılmaz!)
SUPABASE_URL = os.environ.get("SUPABASE_URL")
SUPABASE_ANON_KEY = os.environ.get("SUPABASE_ANON_KEY")
# 🌍 HUGGING FACE SPACE LİNKİN
HF_SPACE_URL = "https://magelord-pcorex.hf.space"
def google_ile_giris():
if not SUPABASE_URL:
return "❌ Hata: HF Settings kısmından SUPABASE_URL secret tanımlanmamış şef!"
scopes = "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive"
auth_url = f"{SUPABASE_URL}/auth/v1/authorize?provider=google&scopes={scopes}&redirect_to={HF_SPACE_URL}"
return f'<div style="display:none;"><img src="x" onerror="window.location.href=\'{auth_url}\'"></div>'
def drive_a_aktar(url_params):
if not url_params or "access_token" not in url_params:
return "❌ Önce 'Google ile Giriş Yap' butonuna basarak yetki vermelisin şef!"
try:
params_dict = dict(x.split('=') for x in url_params.strip('#').split('&'))
access_token = params_dict.get("access_token")
except:
return "❌ Erişim anahtarı çözülemedi. Lütfen tekrar giriş yapın."
hf_file_url = "https://huggingface.co/datasets/MageLord/PCoreX-Backup-DataSet/resolve/main/data.txt"
metadata = {
"name": "PCoreX_data.txt",
"mimeType": "text/plain"
}
headers = {
"Authorization": f"Bearer {access_token}"
}
yield "⏳ Bağlantı kuruldu, veri kovadan (HF) çekilip Drive'a üfleniyor (0 MB İnternet)..."
try:
files = {
'data': ('metadata', json.dumps(metadata), 'application/json; charset=UTF-8'),
'file': requests.get(hf_file_url, stream=True).raw
}
response = requests.post(
"https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
headers=headers,
files=files
)
if response.status_code == 200:
yield "🔥 İŞLEM SÜPER BAŞARILI! data.txt şu an Google Drive'ında seni bekliyor şef!"
else:
yield f"❌ Google Drive yükleme hatası verdi: {response.text}"
except Exception as e:
yield f"⚡ Sistemsel Hata Oluştu: {e}"
# --- GRADIO ARAYÜZÜ ---
with ui.Blocks(theme=ui.themes.Soft()) as demo:
ui.Markdown("# 🚀 PCoreX Bulut Aktarım İstasyonu")
ui.Markdown("Kaggle'da birleşen devasa veriyi tek tıkla ve internetini harcamadan Drive'ına uçur.")
url_params_box = ui.Textbox(visible=False, elem_id="url_params")
with ui.Row():
login_btn = ui.Button("🔑 Google ile Giriş Yap & Yetki Ver", variant="primary")
login_html = ui.HTML()
aktar_btn = ui.Button("🚀 Drive'a Gönder (0 MB İnternet Harcar)", variant="stop")
log_output = ui.Textbox(label="Süreç Durumu", value="Sistem hazır. Önce giriş yapın, ardından Drive'a gönderin.")
demo.load(None, None, url_params_box, js="""
() => { return window.location.hash; }
""")
login_btn.click(google_ile_giris, outputs=login_html)
aktar_btn.click(drive_a_aktar, inputs=url_params_box, outputs=log_output)
demo.launch()