Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,54 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
def
|
|
|
5 |
try:
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
except Exception as e:
|
10 |
-
return f"
|
11 |
|
12 |
def population_agent(task):
|
13 |
-
# بيانات افتراضية (للتجربة
|
14 |
data = {
|
15 |
"مصر": 110_000_000,
|
16 |
"المغرب": 37_000_000
|
17 |
}
|
18 |
|
19 |
-
process_log = []
|
20 |
|
21 |
-
#
|
22 |
-
process_log.append("🔍 جاري جمع بيانات السكان...")
|
23 |
egy_pop = data["مصر"]
|
24 |
mor_pop = data["المغرب"]
|
25 |
-
|
26 |
-
# الخطوة 2: حساب الفرق
|
27 |
diff = egy_pop - mor_pop
|
28 |
-
process_log.append(f"🧮 الفرق الحسابي: {diff:,} نسمة")
|
29 |
-
|
30 |
-
# الخطوة 3: حساب النسبة
|
31 |
percentage = (diff / egy_pop) * 100
|
32 |
-
process_log.append(f"📊 النسبة المئوية: {percentage:.2f}%")
|
33 |
|
34 |
-
#
|
35 |
result = f"""
|
36 |
النتائج:
|
37 |
1. عدد سكان مصر: {egy_pop:,} نسمة
|
38 |
2. عدد سكان المغرب: {mor_pop:,} نسمة
|
39 |
-
3. الفرق: {diff:,} نسمة
|
40 |
4. النسبة: {percentage:.2f}% من سكان مصر
|
41 |
"""
|
42 |
|
43 |
return result, "\n".join(process_log)
|
44 |
|
45 |
with gr.Blocks() as demo:
|
46 |
-
gr.Markdown("## نظام
|
47 |
with gr.Row():
|
48 |
-
task = gr.Textbox(label="المهمة
|
49 |
-
|
50 |
-
btn = gr.Button("نفذ المهمة")
|
51 |
|
52 |
with gr.Row():
|
53 |
-
output = gr.Textbox(label="النتيجة
|
54 |
process = gr.Textbox(label="سجل التنفيذ")
|
55 |
|
56 |
btn.click(population_agent, inputs=task, outputs=[output, process])
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import re
|
4 |
|
5 |
+
def simple_web_search(query):
|
6 |
+
"""بديل بسيط للبحث باستخدام requests"""
|
7 |
try:
|
8 |
+
url = "https://www.google.com/search?q=" + requests.utils.quote(query)
|
9 |
+
headers = {'User-Agent': 'Mozilla/5.0'}
|
10 |
+
response = requests.get(url, headers=headers)
|
11 |
+
|
12 |
+
# استخراج الأرقام من النتائج (مثال بسيط)
|
13 |
+
numbers = re.findall(r'\d[\d,\.]+', response.text)
|
14 |
+
return " ".join(numbers[:3]) if numbers else "لا توجد نتائج"
|
15 |
except Exception as e:
|
16 |
+
return f"خطأ في البحث: {str(e)}"
|
17 |
|
18 |
def population_agent(task):
|
19 |
+
# بيانات افتراضية (للتجربة)
|
20 |
data = {
|
21 |
"مصر": 110_000_000,
|
22 |
"المغرب": 37_000_000
|
23 |
}
|
24 |
|
25 |
+
process_log = ["⚡ تم استخدام بيانات افتراضية"] # سجل التنفيذ
|
26 |
|
27 |
+
# الخطوات الحسابية
|
|
|
28 |
egy_pop = data["مصر"]
|
29 |
mor_pop = data["المغرب"]
|
|
|
|
|
30 |
diff = egy_pop - mor_pop
|
|
|
|
|
|
|
31 |
percentage = (diff / egy_pop) * 100
|
|
|
32 |
|
33 |
+
# النتيجة
|
34 |
result = f"""
|
35 |
النتائج:
|
36 |
1. عدد سكان مصر: {egy_pop:,} نسمة
|
37 |
2. عدد سكان المغرب: {mor_pop:,} نسمة
|
38 |
+
3. الفرق: {diff:,} نسمة
|
39 |
4. النسبة: {percentage:.2f}% من سكان مصر
|
40 |
"""
|
41 |
|
42 |
return result, "\n".join(process_log)
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
+
gr.Markdown("## نظام السكان بدون حزم خارجية")
|
46 |
with gr.Row():
|
47 |
+
task = gr.Textbox(label="المهمة", value="احسب الفرق السكاني بين مصر والمغرب")
|
48 |
+
btn = gr.Button("احسب")
|
|
|
49 |
|
50 |
with gr.Row():
|
51 |
+
output = gr.Textbox(label="النتيجة")
|
52 |
process = gr.Textbox(label="سجل التنفيذ")
|
53 |
|
54 |
btn.click(population_agent, inputs=task, outputs=[output, process])
|