Spaces:
Running
Running
Farhan1572
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,72 @@
|
|
1 |
-
# import dependencies
|
2 |
-
import gradio as gr
|
3 |
-
from openai import OpenAI
|
4 |
-
import os
|
5 |
-
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
finetuned_model = "ft:gpt-3.5-turbo-0125:cedarbyte-business-solutions::9f4vd1FP"
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
|
|
|
|
|
|
40 |
|
41 |
# Gradio interface definition
|
42 |
interface = gr.Interface(
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
)
|
49 |
|
50 |
# Launch the Gradio app
|
51 |
-
|
|
|
|
1 |
+
# # import dependencies
|
2 |
+
# import gradio as gr
|
3 |
+
# from openai import OpenAI
|
4 |
+
# import os
|
5 |
+
# import re
|
6 |
+
|
7 |
+
# # define the openai key
|
8 |
+
# api_key = os.getenv("OPENAI_API_KEY")
|
9 |
+
|
10 |
+
# # make an instance of the openai client
|
11 |
+
# client = OpenAI(api_key = api_key)
|
12 |
+
|
13 |
|
14 |
+
# # finetuned model instance
|
15 |
+
# finetuned_model = "ft:gpt-3.5-turbo-0125:cedarbyte-business-solutions::9f4vd1FP"
|
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 |
+
# humanized_text = response.choices[0].message.content.strip()
|
36 |
+
# humanized_text = re.sub(r'[^A-Za-z0-9\s]', '', humanized_text)
|
37 |
|
38 |
+
# return humanized_text
|
|
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
# # Gradio interface definition
|
42 |
+
# interface = gr.Interface(
|
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 [email protected] for this service"
|
60 |
|
61 |
# Gradio interface definition
|
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 |
# Launch the Gradio app
|
71 |
+
if __name__ == "__main__":
|
72 |
+
interface.launch()
|