djamker commited on
Commit
beb040a
·
verified ·
1 Parent(s): 3d7acd6

Update app.py.txt

Browse files
Files changed (1) hide show
  1. app.py.txt +17 -23
app.py.txt CHANGED
@@ -1,23 +1,17 @@
1
- from transformers import pipeline
2
- import gradio as gr
3
-
4
- # Load the model
5
- clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
6
-
7
- # Define detection function
8
- def detect_ai(text):
9
- result = clf(text)[0]
10
- label = result['label']
11
- score = round(result['score'] * 100, 2)
12
- return f"{label} ({score}%)"
13
-
14
- # Build the interface
15
- demo = gr.Interface(
16
- fn=detect_ai,
17
- inputs="textbox",
18
- outputs="text",
19
- title="AI Text Detector"
20
- )
21
-
22
- # Launch the app
23
- demo.launch()
 
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
+ with gr.Blocks() as demo:
7
+ @gr.api()
8
+ def detect_ai(text: str) -> str:
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
+ demo.launch(show_api=True)