Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +5 -0
- app.py +47 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY . .
|
| 4 |
+
RUN pip install -r requirements.txt
|
| 5 |
+
CMD ["python","app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3, json, os
|
| 2 |
+
from flask import Flask, request, jsonify
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
# download db once
|
| 8 |
+
DB_PATH = hf_hub_download(
|
| 9 |
+
repo_id="Bruhletme/Teligram",
|
| 10 |
+
filename="new.db",
|
| 11 |
+
repo_type="dataset",
|
| 12 |
+
token=os.environ.get("HF_TOKEN")
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
conn = sqlite3.connect(DB_PATH, check_same_thread=False)
|
| 16 |
+
conn.row_factory = sqlite3.Row
|
| 17 |
+
cur = conn.cursor()
|
| 18 |
+
|
| 19 |
+
def fix(v):
|
| 20 |
+
if v is None: return None
|
| 21 |
+
try:
|
| 22 |
+
return v.encode('latin1').decode('utf-8')
|
| 23 |
+
except:
|
| 24 |
+
return v
|
| 25 |
+
|
| 26 |
+
@app.route("/tg")
|
| 27 |
+
def tg():
|
| 28 |
+
q = (request.args.get("id") or "").strip()
|
| 29 |
+
if not q.isdigit():
|
| 30 |
+
return jsonify({"error":"invalid"}), 400
|
| 31 |
+
|
| 32 |
+
cur.execute("SELECT id,phone,username,first_name,last_name FROM users WHERE id=? LIMIT 5",(q,))
|
| 33 |
+
rows = cur.fetchall()
|
| 34 |
+
|
| 35 |
+
if not rows:
|
| 36 |
+
return jsonify({"found":False})
|
| 37 |
+
|
| 38 |
+
data=[]
|
| 39 |
+
for r in rows:
|
| 40 |
+
d=dict(r)
|
| 41 |
+
for k in d:
|
| 42 |
+
d[k]=fix(d[k])
|
| 43 |
+
data.append(d)
|
| 44 |
+
|
| 45 |
+
return jsonify({"found":True,"count":len(data),"results":data})
|
| 46 |
+
|
| 47 |
+
app.run(host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
huggingface_hub
|