debbaghmehdi1 commited on
Commit
6d59000
·
verified ·
1 Parent(s): 29fb5d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -158,40 +158,37 @@ def paraphrase_text(text, replace_ratio=0.6):
158
 
159
  # function to humanize text
160
  def humanize_text(AI_text):
161
- """Humanizes the provided AI text using the fine-tuned model."""
162
  response = client.chat.completions.create(
163
- model=finetuned_model,
164
- temperature = 0.87,
 
 
 
 
165
  messages=[
166
  {"role": "system", "content": """
167
- You are a text humanizer.
168
- You humanize AI generated text.
169
- The text must appear like humanly written.
170
- THE INPUT AND THE OUTPUT HEADINGS MUST BE SAME. NO HEADING SHOULD BE MISSED.
171
- NAMES LIKE NOVEL NAME SHOULD REMAIN INTACT WITHOUT ANY CHANGE.
172
- THE INPUT AND THE OUTPUT SHOULD HAVE SAME WORD COUNT.
173
- THE OUTPUT SENTENCES MUST NOT BE SIMPLE. THEY SHOULD BE COMPOUND, COMPLEX, OR COMPOUND COMPLEX.
174
- ABOVE ALL, THE GRAMMAR AND THE SENSE OF THE SENTENCES MUST BE TOP NOTCH - DO NOT COMPROMISE ON THAT."""},
175
- {"role": "system", "content": "YOU ARE TEXT HUMANIZER BUT YOU DO NOT REDUCE THE LENGTH OF THE SENTENCES. YOUR OUTPUT SENTENCES ARE OF EXACTLY THE SAME LENGTH AS THE INPUT"},
176
- {"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"},
177
- {"role": "user", "content": f"THE GRAMMAR AND THE QUALITY OF THE SENTENCES MUST BE TOP NOTCH - EASY TO UNDERSTAND AND NO GRAMMATICAL ERRORS."},
178
- {"role": "user", "content": "Use as many conjunctions and punctuations to make the sentence long. COMPOUND, COMPLEX, OR COMPOUND COMPLEX sentences are required"},
179
- {"role": "user", "content": f"Humanize the text. Keep the output format i.e. the bullets and the headings as it is. THE GRAMMAR MUST BE TOP NOTCH WITH NO ERRORS AND EASY TO UNDERSTAND!!!!. \nTEXT: {AI_text}"}
180
  ]
181
  )
182
 
183
- return response.choices[0].message.content.strip()
 
 
 
184
 
185
-
186
-
187
- def main_function(AI_text):
188
- humanized_text = humanize_text(AI_text)
189
- # humanized_text= transform_text(humanized_text)
190
  return humanized_text
191
 
192
 
193
 
194
 
 
195
  # Gradio interface definition
196
  interface = gr.Interface(
197
  fn=main_function,
 
158
 
159
  # function to humanize text
160
  def humanize_text(AI_text):
161
+ """Humanizes AI-generated text using GPT + Paraphrasing."""
162
  response = client.chat.completions.create(
163
+ model=finetuned_model, # This remains the same (gpt-3.5-turbo)
164
+ temperature=1.1, # Increased for more variation
165
+ max_tokens=500,
166
+ top_p=0.95,
167
+ frequency_penalty=0.3,
168
+ presence_penalty=0.5,
169
  messages=[
170
  {"role": "system", "content": """
171
+ You are an advanced AI text rewriter that makes AI-generated text sound fully human-written.
172
+ - Use natural synonyms, contractions, and varied sentence structures.
173
+ - Restructure sentences to be complex and nuanced.
174
+ - Avoid robotic phrasing or overly formal structures.
175
+ - Ensure the text feels like it was written by a real person.
176
+ """},
177
+ {"role": "user", "content": f"Rewrite this text to make it more human:\n\n{AI_text}"}
 
 
 
 
 
 
178
  ]
179
  )
180
 
181
+ gpt_output = response.choices[0].message.content.strip()
182
+
183
+ # Apply additional paraphrasing to GPT output
184
+ humanized_text = paraphrase_text(gpt_output)
185
 
 
 
 
 
 
186
  return humanized_text
187
 
188
 
189
 
190
 
191
+
192
  # Gradio interface definition
193
  interface = gr.Interface(
194
  fn=main_function,