|
|
|
import gradio as gr |
|
from openai import OpenAI |
|
import os |
|
|
|
|
|
api_key = os.getenv("OPENAI_API_KEY") |
|
|
|
|
|
client = OpenAI(api_key = api_key) |
|
|
|
|
|
|
|
finetuned_model = "ft:gpt-3.5-turbo-0125:cedarbyte-business-solutions::9e78QK8O" |
|
|
|
|
|
def humanize_text(AI_text): |
|
"""Humanizes the provided AI text using the fine-tuned model.""" |
|
response = completion = client.chat.completions.create( |
|
model=finetuned_model, |
|
messages=[ |
|
{"role": "system", "content": """ |
|
You are a text humanizer. |
|
You humanize AI generated text. |
|
The text must appear like humanly written. |
|
THE INPUT AND THE OUTPUT TEXT SHOULD HAVE THE SAME FORMAT. |
|
THE HEADINGS AND THE BULLETS IN THE INPUT SHOULD REMAIN IN PLACE"""}, |
|
{"role": "user", "content": f"THE LANGUAGE OF THE INPUT AND THE OUTPUT MUST BE SAME. THE SENTENCES SHOULD NOT BE SHORT LENGTH - THEY SHOULD BE SAME AS IN THE INPUT. ALSO THE PARAGRAPHS SHOULD NOT BE SHORT EITHER - PARAGRAPHS MUST HAVE THE SAME LENGTH"}, |
|
{"role": "user", "content": f"Humanize the text. Keep the output format i.e. the bullets and the headings as it is and dont use the list of words that are not permissible. \nTEXT: {AI_text}"} |
|
] |
|
) |
|
|
|
|
|
return response.choices[0].message.content.strip() |
|
|
|
|
|
|
|
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.", |
|
) |
|
|
|
|
|
interface.launch(debug = True) |