djamker commited on
Commit
0f27267
·
verified ·
1 Parent(s): 513571d

Update app.py

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