djamker commited on
Commit
28329d2
·
verified ·
1 Parent(s): c973c9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the model outside the function
5
  clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
6
 
7
- # Define a Gradio Blocks app
8
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
9
 
10
- @gr.api()
11
- def detect_ai(text: str):
12
- try:
13
- if not text.strip():
14
- return "Error: No text provided"
15
- result = clf(text)[0]
16
- label = result['label']
17
- score = round(result['score'] * 100, 2)
18
- return f"{label} ({score}%)"
19
- except Exception as e:
20
- return f"Error: {str(e)}"
21
 
22
- # Important: show_api=True must be passed here
23
- demo.launch(show_api=True)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
5
 
6
+ def detect_ai(text):
7
+ if not text.strip():
8
+ return "No text provided."
9
+ try:
10
+ result = clf(text)[0]
11
+ label = result['label']
12
+ score = round(result['score'] * 100, 2)
13
+ return f"{label} ({score}%)"
14
+ except Exception as e:
15
+ return f"Error: {str(e)}"
16
 
17
+ # Launch the app with a basic Gradio Interface (exposes /predict endpoint)
18
+ demo = gr.Interface(
19
+ fn=detect_ai,
20
+ inputs=gr.Textbox(lines=4, label="Enter text"),
21
+ outputs="text",
22
+ title="AI Text Detector",
23
+ )
 
 
 
 
24
 
25
+ demo.launch()