JohnLicode commited on
Commit
dd40489
·
verified ·
1 Parent(s): 60daedd

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +47 -12
  2. app.py +61 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,12 +1,47 @@
1
- ---
2
- title: Ethics Review Classifier
3
- emoji: 💻
4
- colorFrom: pink
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 6.0.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Ethics Review Classifier
3
+ emoji: 📋
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ # Ethics Review Classifier
14
+
15
+ An AI model to classify research proposal text against ethics review guidelines.
16
+
17
+ ## Usage
18
+
19
+ ### Web Interface
20
+ Use the form above to test the model interactively.
21
+
22
+ ### API Access
23
+ This Space provides a free API endpoint:
24
+
25
+ ```python
26
+ from gradio_client import Client
27
+
28
+ client = Client("JohnLicode/ethics-review-classifier")
29
+ result = client.predict(
30
+ text="The general objective is to develop an AI system...",
31
+ guideline_id="1.1",
32
+ guideline_name="Objectives",
33
+ api_name="/predict"
34
+ )
35
+ print(result)
36
+ ```
37
+
38
+ ### cURL Example
39
+ ```bash
40
+ curl -X POST https://johnlicode-ethics-review-classifier.hf.space/api/predict \
41
+ -H "Content-Type: application/json" \
42
+ -d '{"data": ["Your text here", "1.1", "Objectives"]}'
43
+ ```
44
+
45
+ ## Labels
46
+ - **ADDRESSED**: Text adequately addresses the guideline
47
+ - **NEEDS_REVISION**: Text needs improvement or doesn't address the guideline
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import os
4
+
5
+ # Load model
6
+ print("Loading model...")
7
+ classifier = pipeline(
8
+ "text-classification",
9
+ model="JohnLicode/ethics-review-deberta",
10
+ device="cpu" # Use CPU for free tier
11
+ )
12
+ print("Model loaded!")
13
+
14
+ def classify_ethics(text: str, guideline_id: str = "", guideline_name: str = ""):
15
+ """Classify text for ethics guideline compliance."""
16
+
17
+ # Format input like training data
18
+ if guideline_id and guideline_name:
19
+ input_text = f"Guideline {guideline_id} {guideline_name}: {text}"
20
+ else:
21
+ input_text = text
22
+
23
+ # Truncate if too long
24
+ input_text = input_text[:1500]
25
+
26
+ # Get prediction
27
+ result = classifier(input_text)[0]
28
+
29
+ # Map labels
30
+ label = result['label']
31
+ if label == "LABEL_0":
32
+ label = "ADDRESSED"
33
+ elif label == "LABEL_1":
34
+ label = "NEEDS_REVISION"
35
+
36
+ return {
37
+ "label": label,
38
+ "score": round(result['score'], 4),
39
+ "input_preview": input_text[:100] + "..."
40
+ }
41
+
42
+ # Create Gradio interface
43
+ demo = gr.Interface(
44
+ fn=classify_ethics,
45
+ inputs=[
46
+ gr.Textbox(label="Text to Analyze", lines=5, placeholder="Enter the text from research proposal..."),
47
+ gr.Textbox(label="Guideline ID (optional)", placeholder="e.g., 1.1"),
48
+ gr.Textbox(label="Guideline Name (optional)", placeholder="e.g., Objectives"),
49
+ ],
50
+ outputs=gr.JSON(label="Classification Result"),
51
+ title="Ethics Review Classifier",
52
+ description="Classify research proposal text against ethics guidelines. Returns ADDRESSED or NEEDS_REVISION.",
53
+ examples=[
54
+ ["The general objective is to develop an AI ethics review system. Specific objectives: 1) Create scanning module 2) Implement matching.", "1.1", "Objectives"],
55
+ ["All participant data will be encrypted using AES-256 and stored securely.", "3.2", "Privacy and confidentiality"],
56
+ ["The study explores innovative approaches.", "1.7", "Sampling design and size"],
57
+ ],
58
+ )
59
+
60
+ # Launch with API enabled
61
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
4
+ accelerate
5
+ sentencepiece