onkar-waghmode commited on
Commit
7ef42cd
·
1 Parent(s): ace1287
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -49,8 +49,22 @@ print("Models loaded successfully!")
49
  # AI Detection
50
  # ============================================================================
51
  def predict_ai_content(text):
52
- res = ai_detector_pipe(text)[0]
53
- return res['label'], res['score']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  # ============================================================================
56
  # STAGE 1: PARAPHRASING WITH T5 MODEL
@@ -478,13 +492,13 @@ def create_gradio_interface():
478
 
479
  with gr.Row():
480
  ai_content_label_input = gr.Textbox(
481
- label="AI Content Detection",
482
  interactive=False,
483
  lines=1,
484
  max_lines=10
485
  )
486
  ai_content_score_input = gr.Number(
487
- label="Confidence Score",
488
  precision=2,
489
  interactive=False
490
  )
@@ -494,14 +508,14 @@ def create_gradio_interface():
494
 
495
  with gr.Row():
496
  ai_content_label_generated = gr.Textbox(
497
- label="AI Content Detection",
498
  interactive=False,
499
  lines=1,
500
  max_lines=10
501
  )
502
 
503
  ai_content_score_generated = gr.Number(
504
- label="Confidence Score",
505
  precision=2,
506
  interactive=False
507
  )
 
49
  # AI Detection
50
  # ============================================================================
51
  def predict_ai_content(text):
52
+ if not text or not text.strip():
53
+ return "No input provided", 0.0
54
+
55
+ try:
56
+ result = ai_detector_pipe(text)
57
+ if isinstance(result, list) and len(result) > 0:
58
+ res = result[0]
59
+ ai_content_label = res.get('label', 'Unknown')
60
+ ai_content_score = round(float(res.get('score', 0)) * 100, 2)
61
+ return ai_content_label, ai_content_score
62
+ else:
63
+ return "Invalid response", 0.0
64
+ except Exception as e:
65
+ print(f"Error in prediction: {e}")
66
+ return "Error", 0.0
67
+
68
 
69
  # ============================================================================
70
  # STAGE 1: PARAPHRASING WITH T5 MODEL
 
492
 
493
  with gr.Row():
494
  ai_content_label_input = gr.Textbox(
495
+ label="Detected Content Type",
496
  interactive=False,
497
  lines=1,
498
  max_lines=10
499
  )
500
  ai_content_score_input = gr.Number(
501
+ label="Model Confidence (%)",
502
  precision=2,
503
  interactive=False
504
  )
 
508
 
509
  with gr.Row():
510
  ai_content_label_generated = gr.Textbox(
511
+ label="Detected Content Type",
512
  interactive=False,
513
  lines=1,
514
  max_lines=10
515
  )
516
 
517
  ai_content_score_generated = gr.Number(
518
+ label="Model Confidence (%)",
519
  precision=2,
520
  interactive=False
521
  )