Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,19 +15,24 @@ app.add_middleware(
|
|
| 15 |
allow_headers=["*"],
|
| 16 |
)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
TELEGRAM_BOT_TOKEN = "8830608789:AAEB7OoLGoGFKvyTvZJpwBXM-JeXRXS628U"
|
| 20 |
TELEGRAM_CHAT_ID = "7700628753"
|
| 21 |
|
| 22 |
-
# 👇
|
| 23 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 24 |
HF_DATASET_REPO = "Jitendra55566/Pdf-Storage"
|
| 25 |
|
| 26 |
hf_api = HfApi()
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
@app.post("/upload")
|
| 29 |
async def handle_upload(file: UploadFile = File(...)):
|
| 30 |
-
# 1. फाइल को पढ़ना और यूनिक नाम देना
|
| 31 |
file_bytes = await file.read()
|
| 32 |
unique_filename = f"{uuid.uuid4().hex[:6]}_{file.filename}"
|
| 33 |
|
|
@@ -37,12 +42,12 @@ async def handle_upload(file: UploadFile = File(...)):
|
|
| 37 |
data = {'chat_id': TELEGRAM_CHAT_ID, 'caption': "New PDF Uploaded from Admin Panel"}
|
| 38 |
requests.post(telegram_url, data=data, files=files)
|
| 39 |
|
| 40 |
-
# 3. फाइल को लोकल में सेव करना
|
| 41 |
local_path = f"/tmp/{unique_filename}"
|
| 42 |
with open(local_path, "wb") as f:
|
| 43 |
f.write(file_bytes)
|
| 44 |
|
| 45 |
-
# 4. Hugging Face Dataset पर अपलोड करना
|
| 46 |
hf_api.upload_file(
|
| 47 |
path_or_fileobj=local_path,
|
| 48 |
path_in_repo=unique_filename,
|
|
|
|
| 15 |
allow_headers=["*"],
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# आपकी डिटेल्स
|
| 19 |
TELEGRAM_BOT_TOKEN = "8830608789:AAEB7OoLGoGFKvyTvZJpwBXM-JeXRXS628U"
|
| 20 |
TELEGRAM_CHAT_ID = "7700628753"
|
| 21 |
|
| 22 |
+
# 👇 HF_TOKEN Settings (Secrets) से अपने आप आ जाएगा
|
| 23 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 24 |
HF_DATASET_REPO = "Jitendra55566/Pdf-Storage"
|
| 25 |
|
| 26 |
hf_api = HfApi()
|
| 27 |
|
| 28 |
+
# 👇 यह नया हिस्सा जोड़ा है ताकि आप ब्राउज़र में देख सकें कि ऐप चालू है या नहीं 👇
|
| 29 |
+
@app.get("/")
|
| 30 |
+
def read_root():
|
| 31 |
+
return {"status": "✅ Bot is successfully running!", "message": "Admin Panel API is active."}
|
| 32 |
+
|
| 33 |
@app.post("/upload")
|
| 34 |
async def handle_upload(file: UploadFile = File(...)):
|
| 35 |
+
# 1. फाइल को पढ़ना और यूनिक नाम देना
|
| 36 |
file_bytes = await file.read()
|
| 37 |
unique_filename = f"{uuid.uuid4().hex[:6]}_{file.filename}"
|
| 38 |
|
|
|
|
| 42 |
data = {'chat_id': TELEGRAM_CHAT_ID, 'caption': "New PDF Uploaded from Admin Panel"}
|
| 43 |
requests.post(telegram_url, data=data, files=files)
|
| 44 |
|
| 45 |
+
# 3. फाइल को लोकल में सेव करना
|
| 46 |
local_path = f"/tmp/{unique_filename}"
|
| 47 |
with open(local_path, "wb") as f:
|
| 48 |
f.write(file_bytes)
|
| 49 |
|
| 50 |
+
# 4. Hugging Face Dataset पर अपलोड करना
|
| 51 |
hf_api.upload_file(
|
| 52 |
path_or_fileobj=local_path,
|
| 53 |
path_in_repo=unique_filename,
|