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