mahmoudsaber0 commited on
Commit
f1c8146
·
verified ·
1 Parent(s): 9b17a72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -1,7 +1,6 @@
1
  from fastapi import FastAPI, Request
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
- import uvicorn
5
 
6
  app = FastAPI(title="AI Detector API")
7
 
@@ -11,7 +10,6 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
11
  model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
12
  model.eval()
13
 
14
-
15
  def get_ai_probability(text: str) -> float:
16
  """Return the AI probability (0–100%) for a given text."""
17
  inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
@@ -21,15 +19,15 @@ def get_ai_probability(text: str) -> float:
21
  ai_score = probs[0][1].item() * 100
22
  return round(ai_score, 2)
23
 
 
 
 
 
 
 
24
 
25
  @app.post("/analyze")
26
  async def analyze_text(request: Request):
27
- """
28
- Example body:
29
- {
30
- "text": "Your long article text here"
31
- }
32
- """
33
  data = await request.json()
34
  text = data.get("text", "").strip()
35
  if not text:
@@ -53,7 +51,3 @@ async def analyze_text(request: Request):
53
  "overall_human_score": round(100 - overall, 2),
54
  "paragraphs": results
55
  }
56
-
57
-
58
- if __name__ == "__main__":
59
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
  from fastapi import FastAPI, Request
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
 
4
 
5
  app = FastAPI(title="AI Detector API")
6
 
 
10
  model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME)
11
  model.eval()
12
 
 
13
  def get_ai_probability(text: str) -> float:
14
  """Return the AI probability (0–100%) for a given text."""
15
  inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
 
19
  ai_score = probs[0][1].item() * 100
20
  return round(ai_score, 2)
21
 
22
+ @app.get("/")
23
+ async def home():
24
+ return {
25
+ "message": "Welcome to Saber’s AI Detector API 👋",
26
+ "usage": "Send a POST request to /analyze with JSON {'text': 'your article text'}"
27
+ }
28
 
29
  @app.post("/analyze")
30
  async def analyze_text(request: Request):
 
 
 
 
 
 
31
  data = await request.json()
32
  text = data.get("text", "").strip()
33
  if not text:
 
51
  "overall_human_score": round(100 - overall, 2),
52
  "paragraphs": results
53
  }