File size: 1,293 Bytes
9a4b862
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import requests

# Replace with free HF model that doesn’t require billing
HF_MODEL = "google/flan-t5-small"  # Small free model
HF_API_URL = f"https://api-inference.huggingface.co/models/{HF_MODEL}"
HF_KEY = ""  # Empty if using public free endpoint
HEADERS = {"Authorization": f"Bearer {HF_KEY}"} if HF_KEY else None

def humanize_text(text):
    prompt = f"Rewrite the following text to be human-like, plagiarism-free, and natural:\n{text}"
    payload = {"inputs": prompt}
    try:
        response = requests.post(HF_API_URL, headers=HEADERS, json=payload, timeout=60)
        if response.status_code == 200:
            result = response.json()
            if isinstance(result, list) and "generated_text" in result[0]:
                return result[0]["generated_text"]
            return str(result[0])
        else:
            return f"Error: {response.status_code} - {response.text}"
    except Exception as e:
        return f"Error: {str(e)}"

iface = gr.Interface(
    fn=humanize_text,
    inputs=gr.Textbox(lines=15, placeholder="Paste your text here..."),
    outputs="text",
    title="HumanizeAI — Plagiarism Remover",
    description="Paste your text and click Submit. The AI will rewrite it to be human-like and plagiarism-free."
)

iface.launch()