# app.py import gradio as gr import openai import os # load key from Hugging Face secret openai.api_key = os.getenv("OPENAI_API_KEY") def humanize(text, tone, strength): prompt = f"Rewrite the text in a {tone} tone without shortening:\n\n{text}" res = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": prompt}], max_tokens=len(text.split()) + 200, temperature=0.7 * strength / 10 ) full = res.choices[0].message.content.strip() with open("/tmp/full.txt", "w", encoding="utf-8") as f: f.write(full) return full, "/tmp/full.txt" with gr.Blocks() as demo: txt = gr.Textbox(label="Paste text", lines=15) tone = gr.Dropdown(["Casual","Academic","Marketing","Legal","Creative"], value="Casual") strg = gr.Slider(1,10,value=5,label="Strength") btn = gr.Button("Humanize") out = gr.Textbox(label="Humanized", lines=25) file = gr.File(label="Download") btn.click(humanize,[txt,tone,strg],[out,file]) demo.launch()