abhishekdeshmukh commited on
Commit
ed81b57
·
1 Parent(s): b2c7041

First commit

Browse files
.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="Python 3.8" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
7
+ </project>
.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/textdetectextension.iml" filepath="$PROJECT_DIR$/.idea/textdetectextension.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
.idea/textdetectextension.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
README.md CHANGED
@@ -1,13 +1,27 @@
1
- ---
2
- title: Textdetectextension
3
- emoji: 🚀
4
- colorFrom: blue
5
- colorTo: gray
6
- sdk: gradio
7
- sdk_version: 5.22.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI Text Detection API
2
+
3
+ This API provides endpoints for detecting AI-generated text using the RoBERTa-based model from fakespot-ai.
4
+
5
+ ## API Endpoints
6
+
7
+ - GET `/`: Health check endpoint
8
+ - POST `/predict`: Predict if text is AI-generated or human-written
9
+
10
+ ### Sample Usage
11
+
12
+ POST `/predict`
13
+ ```json
14
+ {
15
+ "text": "Your text to analyze"
16
+ }
17
+ ```
18
+
19
+ Response:
20
+ ```json
21
+ {
22
+ "text": "Your text to analyze",
23
+ "human_probability": 85.5,
24
+ "ai_probability": 14.5,
25
+ "prediction": "Human-written"
26
+ }
27
+ ```
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
5
+ import torch
6
+
7
+ app = FastAPI()
8
+
9
+ # Add CORS middleware
10
+ app.add_middleware(
11
+ CORSMiddleware,
12
+ allow_origins=["*"], # For development - you should restrict this in production
13
+ allow_credentials=True,
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
+ )
17
+
18
+ # Load model and tokenizer
19
+ model_name = "fakespot-ai/roberta-base-ai-text-detection-v1"
20
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
21
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
22
+
23
+
24
+ class TextRequest(BaseModel):
25
+ text: str
26
+
27
+
28
+ @app.post("/predict")
29
+ async def predict(request: TextRequest):
30
+ try:
31
+ # Tokenize the input text
32
+ inputs = tokenizer(request.text, return_tensors="pt", truncation=True, max_length=512)
33
+
34
+ # Make prediction
35
+ with torch.no_grad():
36
+ outputs = model(**inputs)
37
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
38
+
39
+ # Get the probability scores
40
+ human_prob = predictions[0][0].item()
41
+ ai_prob = predictions[0][1].item()
42
+
43
+ return {
44
+ "text": request.text,
45
+ "human_probability": round(human_prob * 100, 2),
46
+ "ai_probability": round(ai_prob * 100, 2),
47
+ "prediction": "AI-generated" if ai_prob > human_prob else "Human-written"
48
+ }
49
+
50
+ except Exception as e:
51
+ raise HTTPException(status_code=500, detail=str(e))
52
+
53
+
54
+ @app.get("/")
55
+ async def root():
56
+ return {"message": "AI Text Detection API is running"}
57
+
58
+
59
+ if __name__ == "__main__":
60
+ import uvicorn
61
+
62
+ uvicorn.run(app, host="0.0.0.0", port=7860)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ fastapi
4
+ uvicorn
5
+ python-multipart