EshahArshad commited on
Commit
81fcd7d
·
verified ·
1 Parent(s): 8bd0a53

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+
5
+ # Define API keys (ensure these are securely handled and not exposed in public code repositories)
6
+ API_KEY = "565c106133mshb641eb3210436aep10e7fbjsn9b12f087ae76"
7
+ API_HOST = "ai-content-identifier2.p.rapidapi.com"
8
+
9
+ # Code for Text AI Detect
10
+ def text_check(user_input):
11
+ url = f"https://{API_HOST}/text"
12
+ payload = {
13
+ "text": user_input,
14
+ "threshold": 10 # Adjust this if needed to test different sensitivity levels
15
+ }
16
+ headers = {
17
+ "x-rapidapi-key": API_KEY,
18
+ "x-rapidapi-host": API_HOST,
19
+ "Content-Type": "application/json"
20
+ }
21
+ try:
22
+ response = requests.post(url, json=payload, headers=headers)
23
+ response.raise_for_status() # Raises an HTTPError for bad responses
24
+ data = response.json()
25
+ # Format the output to be user-friendly
26
+ if 'success' in data and data['success']:
27
+ ai_status = 'Yes' if data['data']['ai'] else 'No'
28
+ return (f"AI Content Detected: {ai_status}\n"
29
+ f"Confidence: {data['data']['percentage']}%\n"
30
+ f"Total Words: {data['data']['stats']['totalWords']}\n"
31
+ f"AI Words: {data['data']['stats']['aiWords']}\n"
32
+ f"Human Words: {data['data']['stats']['humanWords']}\n"
33
+ f"Note: {data['note']}")
34
+ else:
35
+ return "Failed to analyze text. Please try again."
36
+ except requests.exceptions.RequestException as e:
37
+ print(f"Error during API call: {e}")
38
+ return {"error": str(e)}
39
+
40
+ demo = gr.Interface(fn=text_check, inputs="textbox", outputs="textbox")
41
+
42
+ if __name__ == "_main_":
43
+ demo.launch()