Spaces:
Runtime error
Runtime error
Download app.py from SAFE44/test-agent-01: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/SAFE44/test-agent-01/resolve/main/app.py
- Command line
-
hf download hf://spaces/SAFE44/test-agent-01/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SAFE44/test-agent-01/resolve/main/app.py
2.05 kB
| import gradio as gr | |
| import requests | |
| from bs4 import BeautifulSoup | |
| def hunt_properties(location): | |
| if not location: | |
| return "⚠️ يرجى إدخال الوجهة أولاً." | |
| search_url = ( | |
| f"https://html.duckduckgo.com/html/?q=" | |
| f"luxury+apartments+in+{location}+booking" | |
| ) | |
| headers = { | |
| "User-Agent": ( | |
| "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " | |
| "AppleWebKit/537.36 (KHTML, like Gecko) " | |
| "Chrome/120.0.0.0 Safari/537.36" | |
| ) | |
| } | |
| try: | |
| response = requests.get(search_url, headers=headers, timeout=10) | |
| soup = BeautifulSoup(response.text, "html.parser") | |
| results = soup.find_all("a", class_="result__a") | |
| if not results: | |
| return f"❌ لم أجد نتائج مباشرة لـ {location}. حاول كتابة الاسم بالإنجليزية." | |
| output = f"### 🦅 نتائج البحث في {location}:\n\n" | |
| for i, res in enumerate(results[:8], 1): | |
| title = res.get_text(strip=True) | |
| link = res.get("href") | |
| output += f"**{i}.** [{title}]({link})\n\n" | |
| return output | |
| except Exception as e: | |
| return f"❌ خطأ تقني: {e}" | |
| with gr.Blocks(theme=gr.themes.Soft(primary_hue="amber")) as demo: | |
| gr.Markdown("# 🦅 B.com.ly Luxury Finder") | |
| gr.Markdown("محرك بحث وسيط لتجاوز الحظر بطريقة آمنة.") | |
| with gr.Row(): | |
| input_text = gr.Textbox( | |
| label="أين تريد البحث؟", | |
| placeholder="Sicily, London, Tripoli..." | |
| ) | |
| search_btn = gr.Button("بدء الصيد 🎯", variant="primary") | |
| output_md = gr.Markdown("بانتظار أوامرك يا قبطان...") | |
| search_btn.click( | |
| fn=hunt_properties, | |
| inputs=input_text, | |
| outputs=output_md | |
| ) | |
| # 🔴 هذا السطر حاسم – أي خطأ فيه = التطبيق لا يعمل | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |