Spaces:
Runtime error
Runtime error
File size: 7,245 Bytes
1a28b7b 273788e 1a28b7b 273788e 1a28b7b 273788e 1a28b7b 273788e 1a28b7b 273788e 1a28b7b 273788e 1a28b7b a14fe35 4adc33c a14fe35 1a28b7b a14fe35 ca8f926 a14fe35 11a424e a14fe35 1a28b7b b9f798b a14fe35 6f18550 a14fe35 9c554ef a14fe35 11a424e a14fe35 1a28b7b a14fe35 11a424e |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# # # import dependencies
# # import gradio as gr
# # from openai import OpenAI
# # import os
# # import re
# # # define the openai key
# # api_key = "sk-proj-UCoZZMs4MyfyHwXdHjT8T3BlbkFJjYkSZyPfIPNqXfXwoekm"
# # # make an instance of the openai client
# # client = OpenAI(api_key = api_key)
# # # finetuned model instance
# # finetuned_model = "ft:gpt-3.5-turbo-0125:personal::9qGC8cwZ"
# # # 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.86,
# # 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}"}
# # ]
# # )
# # humanized_text = response.choices[0].message.content.strip()
# # return humanized_text
# # # Gradio interface definition
# # interface = gr.Interface(
# # fn=humanize_text,
# # inputs="textbox",
# # outputs="textbox",
# # title="AI Text Humanizer: NoaiGPT.com Demo",
# # description="Enter AI-generated text and get a human-written version.",
# # )
# # # Launch the Gradio app
# # interface.launch(debug = True)
# import gradio as gr
# from openai import OpenAI
# import os
# import re
# from transformers import pipeline
# # define the openai key
# api_key = "sk-proj-UCoZZMs4MyfyHwXdHjT8T3BlbkFJjYkSZyPfIPNqXfXwoekm"
# # make an instance of the openai client
# client = OpenAI(api_key = api_key)
# # finetuned model instance
# finetuned_model = "ft:gpt-3.5-turbo-0125:personal::9qGC8cwZ"
# # Load the AI detection model
# pipe = pipeline("text-classification", model="tommyliphys/ai-detector-distilbert")
# # Define the function to get predictions
# def get_prediction(text):
# return pipe(text)[0]
# # function to humanize the text
# def humanize_text(AI_text):
# """Humanizes the provided AI text using the fine-tuned model."""
# humanized_text = AI_text
# attempts = 0
# max_attempts = 5
# while attempts < max_attempts:
# response = client.chat.completions.create(
# model=finetuned_model,
# temperature=0.85,
# 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": "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: {humanized_text}"}
# ]
# )
# humanized_text = response.choices[0].message.content.strip()
# # Check if the humanized text is still detected as AI
# prediction = get_prediction(humanized_text)
# if prediction['label'] != 'AI':
# break
# attempts += 1
# return humanized_text
# # Gradio interface definition
# interface = gr.Interface(
# fn=humanize_text,
# inputs="textbox",
# outputs="textbox",
# title="AI Text Humanizer: NoaiGPT.com Demo",
# description="Enter AI-generated text and get a human-written version.",
# )
# # Launch the Gradio app
# interface.launch(debug=True)
import gradio as gr
from openai import OpenAI
import os
import re
from transformers import pipeline
# define the openai key
api_key = "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"
# make an instance of the openai client
client = OpenAI(api_key=api_key)
# finetuned model instance
finetuned_model = "ft:gpt-3.5-turbo-0125:personal::9qGC8cwZ"
# Load the AI detection model
pipe = pipeline("text-classification", model="tommyliphys/ai-detector-distilbert")
# Define the function to get predictions
def get_prediction(text):
return pipe(text)[0]
# Function to clean the text
def clean_text(text):
# Remove double asterisks
text = re.sub(r'\*\*', '', text)
# Remove double hash symbols
text = re.sub(r'##', '', text)
return text
# function to humanize the text
def humanize_text(AI_text):
"""Humanizes the provided AI text using the fine-tuned model."""
humanized_text = AI_text
attempts = 0
max_attempts = 10
while attempts < max_attempts:
response = client.chat.completions.create(
model=finetuned_model,
temperature=0.88,
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": "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: {humanized_text}"}
]
)
humanized_text = response.choices[0].message.content.strip()
# Check if the humanized text is still detected as AI
prediction = get_prediction(humanized_text)
if prediction['label'] == 'human' and prediction['score'] > 0.9:
break
attempts += 1
# Clean the humanized text
cleaned_text = clean_text(humanized_text)
return cleaned_text
# Gradio interface definition
interface = gr.Interface(
fn=humanize_text,
inputs="textbox",
outputs="textbox",
title="AI Text Humanizer: NoaiGPT.com Demo",
description="Enter AI-generated text and get a human-written version.",
)
# Launch the Gradio app
interface.launch(debug=True)
|