Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,46 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
|
|
5 |
|
6 |
def detect_ai(text):
|
7 |
-
headers = {"Content-Type": "application/json"}
|
8 |
-
payload = {"inputs": text}
|
9 |
-
response = requests.post(API_URL, headers=headers, json=payload)
|
10 |
try:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
ai_score = item["score"]
|
17 |
-
if "human" in item["label"].lower():
|
18 |
-
human_score = item["score"]
|
19 |
-
result = f"AI confidence: {ai_score*100:.2f}%\nHuman confidence: {human_score*100:.2f}%"
|
20 |
-
result += "\n\nLikely AI" if ai_score > human_score else "\n\nLikely Human"
|
21 |
-
return result
|
22 |
-
except:
|
23 |
-
return "Error: Could not interpret model output."
|
24 |
|
25 |
def rewrite_text(text):
|
26 |
-
# Simple
|
27 |
replacements = {
|
28 |
-
"important": "crucial", "use": "utilize", "
|
29 |
-
"
|
30 |
}
|
31 |
-
for
|
32 |
-
text = text.replace(
|
33 |
return text
|
34 |
|
35 |
-
def
|
36 |
-
return f"You are a teacher.
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
-
gr.Markdown("## AI Detector +
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
52 |
|
53 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
API_URL = "https://api-inference.huggingface.co/models/Hello-SimpleAI/chatgpt-detector-roberta"
|
5 |
+
headers = {"Content-Type": "application/json"}
|
6 |
|
7 |
def detect_ai(text):
|
|
|
|
|
|
|
8 |
try:
|
9 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": text}, timeout=15)
|
10 |
+
result = response.json()
|
11 |
+
return str(result)
|
12 |
+
except Exception as e:
|
13 |
+
return f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def rewrite_text(text):
|
16 |
+
# Simple humanising rewrite
|
17 |
replacements = {
|
18 |
+
"important": "crucial", "use": "utilize", "make": "create",
|
19 |
+
"show": "illustrate", "get": "obtain", "say": "express"
|
20 |
}
|
21 |
+
for word, replacement in replacements.items():
|
22 |
+
text = text.replace(word, replacement)
|
23 |
return text
|
24 |
|
25 |
+
def teacher_feedback_prompt(text):
|
26 |
+
return f"You are a teacher. Give feedback on this writing:\n\n{text}"
|
27 |
|
28 |
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("## AI Detector + Humaniser + Feedback Tool")
|
30 |
+
|
31 |
+
input_text = gr.Textbox(lines=10, label="Enter Text")
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
detect_btn = gr.Button("Detect AI")
|
35 |
+
rewrite_btn = gr.Button("Humanise Text")
|
36 |
+
feedback_btn = gr.Button("Generate Feedback Prompt")
|
37 |
+
|
38 |
+
detect_output = gr.Textbox(label="Detection Result")
|
39 |
+
rewritten_output = gr.Textbox(label="Humanised Text")
|
40 |
+
feedback_output = gr.Textbox(label="Teacher Feedback Prompt")
|
41 |
+
|
42 |
+
detect_btn.click(detect_ai, input_text, detect_output)
|
43 |
+
rewrite_btn.click(rewrite_text, input_text, rewritten_output)
|
44 |
+
feedback_btn.click(teacher_feedback_prompt, rewritten_output, feedback_output)
|
45 |
|
46 |
demo.launch()
|