Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,12 @@ import yaml
|
|
4 |
import os
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
|
|
7 |
|
|
|
|
|
|
|
|
|
8 |
@tool
|
9 |
def summarize_text(text: str, max_length: int = 130) -> str:
|
10 |
"""تلخيص النصوص باستخدام نموذج BART من Hugging Face
|
@@ -19,22 +24,57 @@ def summarize_text(text: str, max_length: int = 130) -> str:
|
|
19 |
data = {
|
20 |
"inputs": text,
|
21 |
"parameters": {"max_length": max_length}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
23 |
@tool
|
24 |
def get_current_time_in_timezone(timezone: str) -> str:
|
25 |
"""أداة لجلب الوقت الحالي في منطقة زمنية محددة.
|
26 |
|
27 |
Args:
|
28 |
-
timezone: سلسلة نصية تمثل منطقة زمنية صالحة (مثال: 'America/New_York')
|
29 |
"""
|
30 |
try:
|
31 |
tz = pytz.timezone(timezone)
|
32 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
DuckDuckGoSearchTool(),
|
35 |
image_generation_tool,
|
36 |
summarize_text,
|
37 |
-
get_current_time_in_timezone
|
38 |
],
|
39 |
max_steps=6,
|
40 |
-
verbosity_level=1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import os
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
7 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
8 |
|
9 |
+
# ----- تصحيح: إضافة الاستيراد الناقص لـ datetime -----
|
10 |
+
import datetime
|
11 |
+
|
12 |
+
# ----- تصحيح: إغلاق الأقواس الناقصة في أداة التلخيص -----
|
13 |
@tool
|
14 |
def summarize_text(text: str, max_length: int = 130) -> str:
|
15 |
"""تلخيص النصوص باستخدام نموذج BART من Hugging Face
|
|
|
24 |
data = {
|
25 |
"inputs": text,
|
26 |
"parameters": {"max_length": max_length}
|
27 |
+
} # <--- إضافة القوس المفقود هنا
|
28 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
29 |
+
response.raise_for_status()
|
30 |
+
summary = response.json()[0]['summary_text']
|
31 |
+
return f"الملخص: {summary}"
|
32 |
+
except Exception as e:
|
33 |
+
return f"خطأ في التلخيص: {str(e)}"
|
34 |
|
35 |
+
# ----- تصحيح: إضافة النقطة في نهاية الجملة الأولى من الـ Docstring -----
|
36 |
@tool
|
37 |
def get_current_time_in_timezone(timezone: str) -> str:
|
38 |
"""أداة لجلب الوقت الحالي في منطقة زمنية محددة.
|
39 |
|
40 |
Args:
|
41 |
+
timezone: سلسلة نصية تمثل منطقة زمنية صالحة (مثال: 'America/New_York')
|
42 |
"""
|
43 |
try:
|
44 |
tz = pytz.timezone(timezone)
|
45 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
46 |
+
return f"The current local time in {timezone} is: {local_time}"
|
47 |
+
except Exception as e:
|
48 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
49 |
+
|
50 |
+
# ----- تصحيح: إضافة تعريف النموذج (model) -----
|
51 |
+
model = HfApiModel(
|
52 |
+
max_tokens=2096,
|
53 |
+
temperature=0.5,
|
54 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
55 |
+
custom_role_conversions=None,
|
56 |
+
)
|
57 |
+
|
58 |
+
# ----- تصحيح: إضافة الأداة المُستوردة من الـ Hub -----
|
59 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
60 |
+
|
61 |
+
# ----- تصحيح: إغلاق الأقواس الناقصة في تعريف الوكيل -----
|
62 |
+
agent = CodeAgent(
|
63 |
+
model=model,
|
64 |
+
tools=[
|
65 |
+
FinalAnswerTool(), # <--- تصحيح: إضافة الأقواس ()
|
66 |
DuckDuckGoSearchTool(),
|
67 |
image_generation_tool,
|
68 |
summarize_text,
|
69 |
+
get_current_time_in_timezone
|
70 |
],
|
71 |
max_steps=6,
|
72 |
+
verbosity_level=1,
|
73 |
+
grammar=None,
|
74 |
+
planning_interval=None,
|
75 |
+
name=None,
|
76 |
+
description=None,
|
77 |
+
prompt_templates=yaml.safe_load(open("prompts.yaml"))
|
78 |
+
)
|
79 |
+
|
80 |
+
GradioUI(agent).launch()
|