FREE-BOT / main.py
ffxbot's picture
Update main.py
0897526 verified
Raw
History Blame Contribute Delete
1.34 kB
from fastapi import FastAPI
from transformers import pipeline
from PIL import Image
import requests
from io import BytesIO
app = FastAPI()
# গুগল-এর ভিশন এআই মডেল
classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
@app.get("/")
def read_root():
return {"status": "✦ FFX ✦ AI Server is Running!"}
@app.get("/analyze")
def analyze(url: str):
try:
# ব্রাউজার সেজে রিকোয়েস্ট পাঠানো যেন টিকটক ব্লক না করে
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64 AppleWebKit/537.36)"}
res = requests.get(url, headers=headers, timeout=15)
img = Image.open(BytesIO(res.content)).convert("RGB")
# AI Processing
results = classifier(img)
top_score = results[0]['score']
if top_score >= 0.85:
return {"success": True, "confidence": f"High ({int(top_score*100)}%)", "names": [results[0]['label'].title()]}
else:
top_3 = [r['label'].title() for r in results[:3]]
return {"success": True, "confidence": "Low", "names": top_3}
except Exception as e:
return {"success": False, "error": str(e)}