File size: 1,597 Bytes
f52ae74
 
 
7700af6
 
f52ae74
 
 
7700af6
 
 
 
 
f52ae74
 
7700af6
f52ae74
7700af6
 
f52ae74
7700af6
 
f52ae74
 
7700af6
 
f52ae74
 
7700af6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f52ae74
 
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
import gradio as gr
import requests

API_URL = "https://api-inference.huggingface.co/models/Hello-SimpleAI/chatgpt-detector-roberta"
headers = {"Content-Type": "application/json"}

def detect_ai(text):
    try:
        response = requests.post(API_URL, headers=headers, json={"inputs": text}, timeout=15)
        result = response.json()
        return str(result)
    except Exception as e:
        return f"Error: {str(e)}"

def rewrite_text(text):
    # Simple humanising rewrite
    replacements = {
        "important": "crucial", "use": "utilize", "make": "create",
        "show": "illustrate", "get": "obtain", "say": "express"
    }
    for word, replacement in replacements.items():
        text = text.replace(word, replacement)
    return text

def teacher_feedback_prompt(text):
    return f"You are a teacher. Give feedback on this writing:\n\n{text}"

with gr.Blocks() as demo:
    gr.Markdown("## AI Detector + Humaniser + Feedback Tool")

    input_text = gr.Textbox(lines=10, label="Enter Text")
    
    with gr.Row():
        detect_btn = gr.Button("Detect AI")
        rewrite_btn = gr.Button("Humanise Text")
        feedback_btn = gr.Button("Generate Feedback Prompt")

    detect_output = gr.Textbox(label="Detection Result")
    rewritten_output = gr.Textbox(label="Humanised Text")
    feedback_output = gr.Textbox(label="Teacher Feedback Prompt")

    detect_btn.click(detect_ai, input_text, detect_output)
    rewrite_btn.click(rewrite_text, input_text, rewritten_output)
    feedback_btn.click(teacher_feedback_prompt, rewritten_output, feedback_output)

demo.launch()