Spaces:
Running
Running
File size: 1,196 Bytes
c3964c3 00886d1 c3964c3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # inference.py
from models import TextModels, ImageModel
from preprocessing import clean_text, load_image_from_url
# инициализация моделей один раз при старте FastAPI
text_model = TextModels()
image_model = ImageModel()
def detect_text(text):
text = clean_text(text)
score = text_model.predict(text)
return {
"type": "text",
"ai_probability": score,
"generation_type": "LLM",
"possible_sources": None
}
def detect_image(url: str):
try:
image = load_image_from_url(url)
score = image_model.predict(image)
return {
"url": url,
"ai_probability": float(score),
"generation_type": "diffusion",
"possible_sources": None
}
except Exception as e:
return {
"url": url,
"error": str(e)
}
# batch detect
def detect_page(texts, images):
"""
texts: list of strings
images: list of URLs
"""
text_results = [detect_text(t) for t in texts]
image_results = [detect_image(i) for i in images]
return {
"texts": text_results,
"images": image_results
} |