CodeXDevloper commited on
Commit
413cf70
·
verified ·
1 Parent(s): 7644512

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -40
app.py CHANGED
@@ -1,48 +1,41 @@
1
- from flask import Flask, request, jsonify
2
- import pandas as pd
3
- from sqlalchemy import create_engine
4
- import os
5
 
6
- app = Flask(__name__)
7
 
8
- # Database connection
9
- DATABASE_URL = os.environ.get('DATABASE_URL', 'postgresql://user:password@localhost:5432/database')
10
- engine = create_engine(DATABASE_URL)
11
-
12
- @app.route('/user/<int:user_id>', methods=['GET'])
13
- def get_user_data(user_id):
14
- """Endpoint to fetch user data by ID"""
15
- try:
16
- # Query database for specific user
17
- query = f"SELECT * FROM your_table WHERE user_id = {user_id}"
18
- df = pd.read_sql(query, engine)
19
-
20
- if df.empty:
21
- return jsonify({'error': 'User not found'}), 404
22
-
23
- return jsonify(df.to_dict('records')), 200
24
 
25
- except Exception as e:
26
- return jsonify({'error': str(e)}), 500
27
-
28
- @app.route('/user/<int:user_id>/csv', methods=['GET'])
29
- def get_user_csv(user_id):
30
- """Endpoint to download user data as CSV"""
31
  try:
32
- query = f"SELECT * FROM your_table WHERE user_id = {user_id}"
33
- df = pd.read_sql(query, engine)
34
 
35
- if df.empty:
36
- return jsonify({'error': 'User not found'}), 404
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- # Return as CSV
39
- return df.to_csv(index=False), 200, {
40
- 'Content-Type': 'text/csv',
41
- 'Content-Disposition': f'attachment; filename=user_{user_id}_data.csv'
42
- }
43
-
44
  except Exception as e:
45
- return jsonify({'error': str(e)}), 500
 
 
 
 
 
 
 
 
46
 
47
- if __name__ == '__main__':
48
- app.run(host='0.0.0.0', port=5000)
 
1
+ import gradio as gr
2
+ from datasets import load_dataset
 
 
3
 
4
+ DATASET = "CodeXDevloper/MergedTgDataset"
5
 
6
+ def search_uid(uid):
7
+ if not uid:
8
+ return {"error": "UID daalo"}
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
 
 
 
 
 
 
10
  try:
11
+ ds = load_dataset(DATASET, split="train", streaming=True)
 
12
 
13
+ for row in ds:
14
+ if uid == str(row.get("user_id", "")).strip():
15
+ return {
16
+ "found": True,
17
+ "user_id": row.get("user_id"),
18
+ "username": row.get("username"),
19
+ "first_name": row.get("first_name"),
20
+ "last_name": row.get("last_name"),
21
+ "phone": row.get("phone"),
22
+ "email": row.get("email"),
23
+ "status": row.get("status"),
24
+ "linked_id": row.get("linked_id"),
25
+ "linked_name": row.get("linked_name"),
26
+ "linked_handle": row.get("linked_handle"),
27
+ }
28
 
29
+ return {"found": False, "message": f"UID '{uid}' nahi mila"}
 
 
 
 
 
30
  except Exception as e:
31
+ return {"error": str(e)}
32
+
33
+ demo = gr.Interface(
34
+ fn=search_uid,
35
+ inputs=gr.Textbox(label="UID daalo", placeholder="385167100"),
36
+ outputs=gr.JSON(label="Result"),
37
+ title="Telegram UID Search",
38
+ description="UID daal ke poore dataset mein search karo"
39
+ )
40
 
41
+ demo.launch()