Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,70 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# import re
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
# # function to humanize the text
|
| 18 |
-
# def humanize_text(AI_text):
|
| 19 |
-
# """Humanizes the provided AI text using the fine-tuned model."""
|
| 20 |
-
# response = completion = client.chat.completions.create(
|
| 21 |
-
# model=finetuned_model,
|
| 22 |
-
# temperature = 0.85,
|
| 23 |
-
# messages=[
|
| 24 |
-
# {"role": "system", "content": """
|
| 25 |
-
# You are a text humanizer.
|
| 26 |
-
# You humanize AI generated text.
|
| 27 |
-
# The text must appear like humanly written.
|
| 28 |
-
# THE INPUT AND THE OUTPUT TEXT SHOULD HAVE THE SAME FORMAT.
|
| 29 |
-
# THE HEADINGS AND THE BULLETS IN THE INPUT SHOULD REMAIN IN PLACE"""},
|
| 30 |
-
# {"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"},
|
| 31 |
-
# {"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}"}
|
| 32 |
-
# ]
|
| 33 |
-
# )
|
| 34 |
|
| 35 |
-
|
| 36 |
-
# humanized_text = re.sub(r'[^A-Za-z0-9\s]', '', humanized_text)
|
| 37 |
|
| 38 |
-
# return humanized_text
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
# fn=humanize_text,
|
| 44 |
-
# inputs="textbox",
|
| 45 |
-
# outputs="textbox",
|
| 46 |
-
# title="AI Text Humanizer",
|
| 47 |
-
# description="Enter AI-generated text and get a human-written version.",
|
| 48 |
-
# )
|
| 49 |
|
| 50 |
-
# # Launch the Gradio app
|
| 51 |
-
# interface.launch(debug = True)
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
-
import gradio as gr
|
| 56 |
|
| 57 |
-
# Function to handle text submission
|
| 58 |
-
def contact_info(text):
|
| 59 |
-
return "Contact farhan.sid1111@gmail.com for Humanizer Application service"
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
interface = gr.Interface(
|
| 63 |
-
fn=contact_info,
|
| 64 |
-
inputs="textbox",
|
| 65 |
-
outputs="text",
|
| 66 |
-
title="Contact Information",
|
| 67 |
-
description="Enter text and click submit to get contact information."
|
| 68 |
-
)
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import dependencies
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
import os
|
|
|
|
| 5 |
|
| 6 |
+
# define the openai key
|
| 7 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
|
| 9 |
+
# make an instance of the openai client
|
| 10 |
+
client = OpenAI(api_key = api_key)
|
| 11 |
|
| 12 |
+
# finetuned model instance
|
| 13 |
+
finetuned_model = "ft:gpt-3.5-turbo-0125:personal::9rCHMo9V"
|
| 14 |
|
| 15 |
+
# function to humanize the text
|
| 16 |
+
def humanize_text(AI_text):
|
| 17 |
+
"""Humanizes the provided AI text using the fine-tuned model."""
|
| 18 |
+
response = completion = client.chat.completions.create(
|
| 19 |
+
model=finetuned_model,
|
| 20 |
+
messages=[
|
| 21 |
+
{"role": "system", "content": """
|
| 22 |
+
You are a text humanizer.
|
| 23 |
+
You humanize AI generated text.
|
| 24 |
+
The text must appear like humanly written.
|
| 25 |
+
THE INPUT AND THE OUTPUT TEXT SHOULD HAVE THE SAME FORMAT.
|
| 26 |
+
THE HEADINGS AND THE BULLETS IN THE INPUT SHOULD REMAIN IN PLACE"""},
|
| 27 |
+
{"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"},
|
| 28 |
+
{"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}"}
|
| 29 |
+
]
|
| 30 |
+
)
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
return response.choices[0].message.content.strip()
|
|
|
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
+
# Gradio interface definition
|
| 37 |
+
interface = gr.Interface(
|
| 38 |
+
fn=humanize_text,
|
| 39 |
+
inputs="textbox",
|
| 40 |
+
outputs="textbox",
|
| 41 |
+
title="AI Text Humanizer",
|
| 42 |
+
description="Enter AI-generated text and get a human-written version.",
|
| 43 |
+
)
|
| 44 |
|
| 45 |
+
# Launch the Gradio app
|
| 46 |
+
interface.launch(debug = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
|
|
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
|
|
|
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
# import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
# # Function to handle text submission
|
| 56 |
+
# def contact_info(text):
|
| 57 |
+
# return "Contact farhan.sid1111@gmail.com for Humanizer Application service"
|
| 58 |
+
|
| 59 |
+
# # Gradio interface definition
|
| 60 |
+
# interface = gr.Interface(
|
| 61 |
+
# fn=contact_info,
|
| 62 |
+
# inputs="textbox",
|
| 63 |
+
# outputs="text",
|
| 64 |
+
# title="AI TEXT HUMANIZER",
|
| 65 |
+
# description="Enter AI text and get its humanizer equivalent"
|
| 66 |
+
# )
|
| 67 |
+
|
| 68 |
+
# # Launch the Gradio app
|
| 69 |
+
# if __name__ == "__main__":
|
| 70 |
+
# interface.launch()
|