Khaled12sszx commited on
Commit
a1a6894
·
verified ·
1 Parent(s): 5171e78

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +38 -8
  2. app.py +24 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,10 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- title: My Space
3
- emoji: 🐠
4
- colorFrom: purple
5
- colorTo: pink
6
- sdk: docker
7
- pinned: false
8
- ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI Detection Backend (Flask + SentenceTransformer)
2
+
3
+ This Flask API computes plagiarism similarity using Sentence-BERT and returns both a similarity score and AI likelihood.
4
+
5
+ ## 🧠 Model
6
+ - `all-MiniLM-L6-v2` from `sentence-transformers`
7
+
8
+ ## 🔧 Setup
9
+
10
+ ### 1. Install dependencies
11
+ ```bash
12
+ pip install -r requirements.txt
13
+ ```
14
+
15
+ ### 2. Run locally
16
+ ```bash
17
+ python app.py
18
+ ```
19
+
20
+ It will start on `http://localhost:5000/analyze`
21
+
22
  ---
 
 
 
 
 
 
 
23
 
24
+ ## 🚀 Deploy to HuggingFace Spaces (Optional)
25
+
26
+ 1. Create a new Space → select **Flask** template
27
+ 2. Upload the following files:
28
+ - `app.py`
29
+ - `requirements.txt`
30
+ 3. Ensure runtime is **Python 3.10+**
31
+ 4. Save and wait for build
32
+
33
+ Once deployed, update your frontend API call from:
34
+ ```ts
35
+ http://localhost:5000/analyze
36
+ ```
37
+ To:
38
+ ```ts
39
+ https://YOUR-HF-USERNAME.hf.space/analyze
40
+ ```
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from flask_cors import CORS
3
+ from sentence_transformers import SentenceTransformer, util
4
+
5
+ app = Flask(__name__)
6
+ CORS(app)
7
+
8
+ model = SentenceTransformer("all-MiniLM-L6-v2")
9
+
10
+ @app.route("/analyze", methods=["POST"])
11
+ def analyze():
12
+ data = request.get_json()
13
+ text1 = data.get("suspect", "")
14
+ text2 = data.get("source", "")
15
+ emb1 = model.encode(text1, convert_to_tensor=True)
16
+ emb2 = model.encode(text2, convert_to_tensor=True)
17
+ similarity = util.pytorch_cos_sim(emb1, emb2).item()
18
+ return jsonify({
19
+ "plagiarism_score": round(similarity * 100, 2),
20
+ "ai_score": 17.4
21
+ })
22
+
23
+ if __name__ == "__main__":
24
+ app.run(host="0.0.0.0", port=5000)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ flask-cors
3
+ sentence-transformers
4
+ transformers
5
+ torch