import gradio as gr
from generated_text_detector.utils.text_detector import GeneratedTextDetector

# Инициализация детектора
detector = GeneratedTextDetector(
    "SuperAnnotate/ai-detector",
    device="cuda",
    preprocessing=True
)

# Функция для предсказания
def detect_generated_text(input_text):
    try:
        result = detector.detect_report(input_text)
        return f"Detection Result:\n\n{result}"
    except Exception as e:
        return f"Error: {str(e)}"

# Создание интерфейса Gradio
interface = gr.Interface(
    fn=detect_generated_text,
    inputs=gr.Textbox(
        lines=5,
        placeholder="Enter text here to check if it's AI-generated...",
        label="Input Text"
    ),
    outputs=gr.Textbox(label="Detection Result"),
    title="AI-Generated Text Detector",
    description="Enter any text to determine if it was generated by AI. Powered by SuperAnnotate/ai-detector model.",
    examples=[
        ["It's not uncommon for people to develop allergies or intolerances to certain foods as they get older."],
        ["The quick brown fox jumps over the lazy dog near the river bank on a sunny afternoon."]
    ]
)

# Запуск интерфейса
if __name__ == "__main__":
    interface.launch()