hassamniaz7 commited on
Commit
bddc534
·
verified ·
1 Parent(s): 2e3f138

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -42,19 +42,19 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
42
  pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
43
 
44
  def classify_text(text):
45
- start_time = time.time()
46
 
47
- # Get results with all scores returned
48
  results = pipe(text, return_all_scores=True)
49
 
50
- end_time = time.time()
51
 
52
  output = f"Sentence: {text}\n"
53
 
54
- # Sort results by score in descending order
55
  sorted_results = sorted(results[0], key=lambda x: x['score'], reverse=True)
56
 
57
- # Print the top 3 highest-scoring labels and scores
58
  for i, result in enumerate(sorted_results[:3]): # Limiting to the top 3 results
59
  output += f"Label {i+1}: {result['label']}, Score: {result['score']:.4f}\n"
60
 
@@ -62,7 +62,7 @@ def classify_text(text):
62
 
63
  return output
64
 
65
- # Gradio Interface
66
  gr.Interface(
67
  fn=classify_text,
68
  title="Sentiment Classifier",
 
42
  pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
43
 
44
  def classify_text(text):
45
+ # start_time = time.time()
46
 
47
+
48
  results = pipe(text, return_all_scores=True)
49
 
50
+ # end_time = time.time()
51
 
52
  output = f"Sentence: {text}\n"
53
 
54
+
55
  sorted_results = sorted(results[0], key=lambda x: x['score'], reverse=True)
56
 
57
+
58
  for i, result in enumerate(sorted_results[:3]): # Limiting to the top 3 results
59
  output += f"Label {i+1}: {result['label']}, Score: {result['score']:.4f}\n"
60
 
 
62
 
63
  return output
64
 
65
+
66
  gr.Interface(
67
  fn=classify_text,
68
  title="Sentiment Classifier",