import gradio as gr import requests import json # Define API keys (ensure these are securely handled and not exposed in public code repositories) API_KEY = "565c106133mshb641eb3210436aep10e7fbjsn9b12f087ae76" API_HOST = "ai-content-identifier2.p.rapidapi.com" # Code for Text AI Detect def text_check(user_input): url = f"https://{API_HOST}/text" payload = { "text": user_input, "threshold": 10 # Adjust this if needed to test different sensitivity levels } headers = { "x-rapidapi-key": API_KEY, "x-rapidapi-host": API_HOST, "Content-Type": "application/json" } try: response = requests.post(url, json=payload, headers=headers) response.raise_for_status() # Raises an HTTPError for bad responses data = response.json() # Format the output to be user-friendly if 'success' in data and data['success']: ai_status = 'Yes' if data['data']['ai'] else 'No' return (f"AI Content Detected: {ai_status}\n" f"Confidence: {data['data']['percentage']}%\n" f"Total Words: {data['data']['stats']['totalWords']}\n" f"AI Words: {data['data']['stats']['aiWords']}\n" f"Human Words: {data['data']['stats']['humanWords']}\n" f"Note: {data['note']}") else: return "Failed to analyze text. Please try again." except requests.exceptions.RequestException as e: print(f"Error during API call: {e}") return {"error": str(e)} demo = gr.Interface(fn=text_check, inputs="textbox", outputs="textbox") if __name__ == "_main_": demo.launch()