anuroopageorge commited on
Commit
3c697f4
·
verified ·
1 Parent(s): dc85e85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -34,23 +34,28 @@ def get_square_root_tool(input_number:int)-> int: #it's import to specify the re
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
  text: The content of the educational article to be classified.
42
  Returns:
43
- int: 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
 
 
34
  return f"Error fetching Square root of '{input_number}': {str(e)}"
35
 
36
  @tool
37
+ def classify_educational_article(text: str) -> str:
38
  """
39
  Classifier for judging the educational value of web pages.
40
  Args:
41
  text: The content of the educational 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 AutoTokenizer, AutoModelForSequenceClassification
46
+ tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/fineweb-edu-classifier")
47
+ model = AutoModelForSequenceClassification.from_pretrained("HuggingFaceTB/fineweb-edu-classifier")
 
48
  inputs = tokenizer(text, return_tensors="pt", padding="longest", truncation=True)
49
+ outputs = model(**inputs)
50
  logits = outputs.logits.squeeze(-1).float().detach().numpy()
51
  score = logits.item()
52
+ result = {
53
+ "text": text,
54
+ "score": score,
55
+ "int_score": int(round(max(0, min(score, 5)))),
56
+ }
57
+
58
+ return result
59
 
60
 
61