djamker commited on
Commit
fc186ef
·
verified ·
1 Parent(s): f7d8953

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -3,12 +3,16 @@ 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(show_api=True)
 
3
 
4
  clf = pipeline("text-classification", model="MayZhou/e5-small-lora-ai-generated-detector")
5
 
6
+ # Create API function inside Blocks context
7
  with gr.Blocks() as demo:
8
  @gr.api()
9
+ def detect_ai(text: str) -> str:
10
+ try:
11
+ result = clf(text)[0]
12
+ label = result['label']
13
+ score = round(result['score'] * 100, 2)
14
+ return f"{label} ({score}%)"
15
+ except Exception as e:
16
+ return f"Error: {str(e)}"
17
 
18
+ demo.launch(server_name="0.0.0.0", show_api=True)