| import gradio as gr |
| import duckdb |
|
|
| PARQUET_URL = "https://huggingface.co/datasets/aryan620501/Inddatainonefile/resolve/main/users_data.parquet" |
|
|
| con = duckdb.connect() |
| con.execute("INSTALL httpfs; LOAD httpfs;") |
| con.execute(f"CREATE OR REPLACE VIEW users_view AS SELECT * FROM read_parquet('{PARQUET_URL}')") |
| print("DuckDB view ready!") |
|
|
| def search_mobile(mobile: str): |
| if not mobile.strip(): |
| return {"status": "error", "message": "Mobile number daaliye."} |
| try: |
| query = """ |
| SELECT mobile, name, fname, address, alt, circle, id, email |
| FROM users_view |
| WHERE mobile = ? |
| LIMIT 1 |
| """ |
| result = con.execute(query, [str(mobile)]).fetchall() |
| if not result: |
| return {"status": "error", "message": f"Mobile number {mobile} nahi mila."} |
| columns = [desc[0] for desc in con.description] |
| row_dict = dict(zip(columns, result[0])) |
| return {"status": "success", "data": row_dict} |
| except Exception as e: |
| return {"status": "error", "message": "Query timeout ya process nahi ho payi."} |
|
|
| with gr.Blocks(title="Number to Info", theme=gr.themes.Soft()) as demo: |
| gr.Markdown("# 📱 Number to Info API") |
| gr.Markdown("Mobile number daaliye aur info prapt karein.") |
|
|
| with gr.Row(): |
| mobile_input = gr.Textbox(label="Mobile Number", placeholder="Enter mobile number...", scale=3) |
| search_btn = gr.Button("Search", variant="primary", scale=1) |
|
|
| output = gr.JSON(label="Result") |
|
|
| search_btn.click(fn=search_mobile, inputs=mobile_input, outputs=output) |
| mobile_input.submit(fn=search_mobile, inputs=mobile_input, outputs=output) |
|
|
| if __name__ == "__main__": |
| demo.launch(server_name="0.0.0.0", server_port=7860) |
|
|