NoaiGPT commited on
Commit
dd02c0c
·
1 Parent(s): 669daf3
Files changed (1) hide show
  1. app.py +96 -26
app.py CHANGED
@@ -1,8 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "sk-proj-UCoZZMs4MyfyHwXdHjT8T3BlbkFJjYkSZyPfIPNqXfXwoekm"
@@ -10,41 +62,59 @@ api_key = "sk-proj-UCoZZMs4MyfyHwXdHjT8T3BlbkFJjYkSZyPfIPNqXfXwoekm"
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:personal::9qGC8cwZ"
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.90,
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
-
37
- return humanized_text
 
 
 
 
 
 
 
 
 
 
 
38
 
 
39
 
40
  # Gradio interface definition
41
  interface = gr.Interface(
42
- fn=humanize_text,
43
- inputs="textbox",
44
- outputs="textbox",
45
- title="AI Text Humanizer: NoaiGPT.com Demo",
46
- description="Enter AI-generated text and get a human-written version.",
47
  )
48
 
49
  # Launch the Gradio app
50
- interface.launch(debug = True)
 
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 = "sk-proj-UCoZZMs4MyfyHwXdHjT8T3BlbkFJjYkSZyPfIPNqXfXwoekm"
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:personal::9qGC8cwZ"
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
+
37
+ # return humanized_text
38
+
39
+
40
+ # # Gradio interface definition
41
+ # interface = gr.Interface(
42
+ # fn=humanize_text,
43
+ # inputs="textbox",
44
+ # outputs="textbox",
45
+ # title="AI Text Humanizer: NoaiGPT.com Demo",
46
+ # description="Enter AI-generated text and get a human-written version.",
47
+ # )
48
+
49
+ # # Launch the Gradio app
50
+ # interface.launch(debug = True)
51
+
52
  # import dependencies
53
  import gradio as gr
54
  from openai import OpenAI
55
  import os
56
  import re
57
+ from transformers import pipeline
58
 
59
  # define the openai key
60
  api_key = "sk-proj-UCoZZMs4MyfyHwXdHjT8T3BlbkFJjYkSZyPfIPNqXfXwoekm"
 
62
  # make an instance of the openai client
63
  client = OpenAI(api_key = api_key)
64
 
 
65
  # finetuned model instance
66
  finetuned_model = "ft:gpt-3.5-turbo-0125:personal::9qGC8cwZ"
67
 
68
+ # Load the AI detection model
69
+ pipe = pipeline("text-classification", model="tommyliphys/ai-detector-distilbert")
70
+
71
+ # Define the function to get predictions
72
+ def get_prediction(text):
73
+ return pipe(text)[0]
74
+
75
  # function to humanize the text
76
  def humanize_text(AI_text):
77
+ """Humanizes the provided AI text using the fine-tuned model."""
78
+ humanized_text = AI_text
79
+ attempts = 0
80
+ max_attempts = 3
81
+
82
+ while attempts < max_attempts:
83
+ response = client.chat.completions.create(
84
+ model=finetuned_model,
85
+ temperature=0.85,
86
+ messages=[
87
+ {"role": "system", "content": """
88
+ You are a text humanizer.
89
+ You humanize AI generated text.
90
+ The text must appear like humanly written.
91
+ THE INPUT AND THE OUTPUT TEXT SHOULD HAVE THE SAME FORMAT.
92
+ THE HEADINGS AND THE BULLETS IN THE INPUT SHOULD REMAIN IN PLACE"""},
93
+ {"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"},
94
+ {"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}"}
95
+ ]
96
+ )
97
+
98
+ humanized_text = response.choices[0].message.content.strip()
99
+
100
+ # Check if the humanized text is still detected as AI
101
+ prediction = get_prediction(humanized_text)
102
+
103
+ if prediction['label'] != 'AI' or prediction['score'] < 0.9:
104
+ break
105
+
106
+ attempts += 1
107
 
108
+ return humanized_text
109
 
110
  # Gradio interface definition
111
  interface = gr.Interface(
112
+ fn=humanize_text,
113
+ inputs="textbox",
114
+ outputs="textbox",
115
+ title="AI Text Humanizer: NoaiGPT.com Demo",
116
+ description="Enter AI-generated text and get a human-written version.",
117
  )
118
 
119
  # Launch the Gradio app
120
+ interface.launch(debug=True)