mia37938 commited on
Commit
f52ae74
·
verified ·
1 Parent(s): d4fcb9d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ API_URL = "https://api-inference.huggingface.co/models/robinhad/roberta-base-openai-detector"
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
+ output = response.json()
12
+ ai_score = 0
13
+ human_score = 0
14
+ for item in output:
15
+ if "ai" in item["label"].lower():
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 rewriting logic
27
+ replacements = {
28
+ "important": "crucial", "use": "utilize", "show": "demonstrate",
29
+ "get": "obtain", "make": "create", "say": "express"
30
+ }
31
+ for key, value in replacements.items():
32
+ text = text.replace(key, value)
33
+ return text
34
+
35
+ def feedback_prompt(text):
36
+ return f"You are a teacher. Please give feedback on the following writing:\n\n{text}"
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("## AI Detector + Rewriter + Feedback Prompt Generator")
40
+ text_input = gr.Textbox(lines=10, label="Enter Text")
41
+ detect_btn = gr.Button("Detect AI")
42
+ rewrite_btn = gr.Button("Rewrite Text")
43
+ feedback_btn = gr.Button("Generate Feedback Prompt")
44
+
45
+ ai_output = gr.Textbox(label="Detection Result")
46
+ rewritten = gr.Textbox(label="Rewritten Text")
47
+ feedback = gr.Textbox(label="Teacher Prompt")
48
+
49
+ detect_btn.click(detect_ai, text_input, ai_output)
50
+ rewrite_btn.click(rewrite_text, text_input, rewritten)
51
+ feedback_btn.click(feedback_prompt, rewritten, feedback)
52
+
53
+ demo.launch()