CyberTea commited on
Commit
76e9ce0
·
verified ·
1 Parent(s): 7df4334

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -26
app.py CHANGED
@@ -1,33 +1,38 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Инициализация пайплайна для классификации текста
5
- pipe = pipeline("text-classification", model="SuperAnnotate/ai-detector")
 
 
 
 
6
 
7
- def classify_text(input_text):
8
- # Получаем предсказание от модели
9
- result = pipe(input_text)
10
-
11
- # Извлекаем метку и вероятность
12
- label = result[0]['label']
13
- score = result[0]['score']
14
-
15
- # Форматируем результат
16
- if label == 'POSITIVE':
17
- interpretation = "Текст похож на сгенерированный ИИ"
18
- else:
19
- interpretation = "Текст похож на человеческий"
20
-
21
- return f"Результат: {interpretation}\nВероятность: {score:.2%}"
22
 
23
- # Создаем интерфейс Gradio
24
  interface = gr.Interface(
25
- fn=classify_text,
26
- inputs=gr.Textbox(lines=5, placeholder="Введите текст здесь..."),
27
- outputs="text",
28
- title="Детектор текста ИИ",
29
- description="Введите текст, чтобы определить, похож ли он на сгенерированный ИИ или написанный человеком."
 
 
 
 
 
 
 
 
30
  )
31
 
32
- # Запускаем интерфейс
33
- interface.launch()
 
 
1
  import gradio as gr
2
+ from generated_text_detector.utils.text_detector import GeneratedTextDetector
3
 
4
+ # Инициализация детектора
5
+ detector = GeneratedTextDetector(
6
+ "SuperAnnotate/ai-detector",
7
+ device="cuda",
8
+ preprocessing=True
9
+ )
10
 
11
+ # Функция для предсказания
12
+ def detect_generated_text(input_text):
13
+ try:
14
+ result = detector.detect_report(input_text)
15
+ return f"Detection Result:\n\n{result}"
16
+ except Exception as e:
17
+ return f"Error: {str(e)}"
 
 
 
 
 
 
 
 
18
 
19
+ # Создание интерфейса Gradio
20
  interface = gr.Interface(
21
+ fn=detect_generated_text,
22
+ inputs=gr.Textbox(
23
+ lines=5,
24
+ placeholder="Enter text here to check if it's AI-generated...",
25
+ label="Input Text"
26
+ ),
27
+ outputs=gr.Textbox(label="Detection Result"),
28
+ title="AI-Generated Text Detector",
29
+ description="Enter any text to determine if it was generated by AI. Powered by SuperAnnotate/ai-detector model.",
30
+ examples=[
31
+ ["It's not uncommon for people to develop allergies or intolerances to certain foods as they get older."],
32
+ ["The quick brown fox jumps over the lazy dog near the river bank on a sunny afternoon."]
33
+ ]
34
  )
35
 
36
+ # Запуск интерфейса
37
+ if __name__ == "__main__":
38
+ interface.launch()