Farhan1572 commited on
Commit
5116a58
·
verified ·
1 Parent(s): 10d94f5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "sk-proj-PGFdFEaxESEjPvvDiisET3BlbkFJwof4S5zHhSjDgMJqfree"
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)