Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,6 +33,27 @@ def get_square_root_tool(input_number:int)-> int: #it's import to specify the re
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching Square root of '{input_number}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
@tool
|
37 |
def get_current_time_in_timezone(timezone: str) -> str:
|
38 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -70,7 +91,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
70 |
|
71 |
agent = CodeAgent(
|
72 |
model=model,
|
73 |
-
tools=[final_answer,image_generation_tool,get_square_root_tool], ## add your tools here (don't remove final answer)
|
74 |
max_steps=6,
|
75 |
verbosity_level=1,
|
76 |
grammar=None,
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching Square root of '{input_number}': {str(e)}"
|
35 |
|
36 |
+
@tool
|
37 |
+
def classify_educational_article(text: str) -> int:
|
38 |
+
"""
|
39 |
+
Classifier for judging the educational value of web pages.
|
40 |
+
Args:
|
41 |
+
article_text: The content of the news article to be classified.
|
42 |
+
Returns:
|
43 |
+
str: This function will output a dictionary with the input text, the predicted score, and an integer score between 0 and 5
|
44 |
+
"""
|
45 |
+
from transformers import pipeline
|
46 |
+
# Perform classification
|
47 |
+
model_name = "HuggingFaceTB/fineweb-edu-classifier"
|
48 |
+
classifier = pipeline("text-classification", model=model_name)
|
49 |
+
inputs = tokenizer(text, return_tensors="pt", padding="longest", truncation=True)
|
50 |
+
outputs = classifier(**inputs)
|
51 |
+
logits = outputs.logits.squeeze(-1).float().detach().numpy()
|
52 |
+
score = logits.item()
|
53 |
+
return score
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
@tool
|
58 |
def get_current_time_in_timezone(timezone: str) -> str:
|
59 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
91 |
|
92 |
agent = CodeAgent(
|
93 |
model=model,
|
94 |
+
tools=[final_answer,image_generation_tool,get_square_root_tool,classify_educational_article], ## add your tools here (don't remove final answer)
|
95 |
max_steps=6,
|
96 |
verbosity_level=1,
|
97 |
grammar=None,
|