Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
@@ -33,6 +34,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
@@ -55,7 +78,11 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[
|
|
|
|
|
|
|
|
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
import os # أضف هذا الاستيراد في الأعلى
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
34 |
except Exception as e:
|
35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
36 |
|
37 |
+
@tool
|
38 |
+
def summarize_text(text: str, max_length: int = 130) -> str:
|
39 |
+
"""تلخيص النصوص باستخدام نموذج BART من Hugging Face
|
40 |
+
Args:
|
41 |
+
text: النص الأصلي المراد تلخيصه
|
42 |
+
max_length: الحد الأقصى لطول الملخص (افتراضي: 130 كلمة)
|
43 |
+
"""
|
44 |
+
try:
|
45 |
+
# استخدام نموذج التلخيص من Hugging Face
|
46 |
+
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
47 |
+
headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"}
|
48 |
+
data = {
|
49 |
+
"inputs": text,
|
50 |
+
"parameters": {"max_length": max_length}
|
51 |
+
}
|
52 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
53 |
+
response.raise_for_status()
|
54 |
+
summary = response.json()[0]['summary_text']
|
55 |
+
return f"الملخص: {summary}"
|
56 |
+
except Exception as e:
|
57 |
+
return f"خطأ في التلخيص: {str(e)}"
|
58 |
+
|
59 |
|
60 |
final_answer = FinalAnswerTool()
|
61 |
|
|
|
78 |
|
79 |
agent = CodeAgent(
|
80 |
model=model,
|
81 |
+
tools=[
|
82 |
+
final_answer,
|
83 |
+
DuckDuckGoSearchTool,
|
84 |
+
image_generation_tool,
|
85 |
+
summarize_text], ## add your tools here (don't remove final answer)
|
86 |
max_steps=6,
|
87 |
verbosity_level=1,
|
88 |
grammar=None,
|