Spaces:
Running
Running
# import dependencies | |
import gradio as gr | |
from openai import OpenAI | |
import os | |
# define the openai key | |
api_key = os.getenv("OPENAI_API_KEY") | |
# make an instance of the openai client | |
client = OpenAI(api_key = api_key) | |
# finetuned model instance | |
finetuned_model = "ft:gpt-3.5-turbo-0125:cedarbyte-business-solutions::AgGF39px" | |
# function to humanize the text | |
def humanize_text(AI_text): | |
"""Humanizes the provided AI text using the fine-tuned model.""" | |
response = completion = client.chat.completions.create( | |
model=finetuned_model, | |
temperature = 0.9, | |
messages=[ | |
{"role": "system", "content": """ | |
You are a text humanizer. | |
You humanize AI generated text."""}, | |
{"role": "user", "content": f"Humanize the text. Must not be detected by any of the AI detectors out there.\nTEXT: {AI_text}"} | |
] | |
) | |
return response.choices[0].message.content.strip() | |
# Gradio interface definition | |
interface = gr.Interface( | |
fn=humanize_text, | |
inputs="textbox", | |
outputs="textbox", | |
title="AI Text Humanizer", | |
description="Enter AI-generated text and get a human-written version.", | |
) | |
# Launch the Gradio app | |
interface.launch(debug = True) |