Jan Philip Wahle commited on
Commit
707d7e1
1 Parent(s): aa3742a

Update default type

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -10,17 +10,23 @@ import openai
10
 
11
  openai.api_key = os.environ.get("OPENAI_API_KEY")
12
 
 
13
  def create_prompt(sentence, paraphrase_type):
14
  prompt = {
15
  "messages": [
16
  {
17
  "role": "user",
18
- "content": f"Given the following sentence, generate a paraphrase with the following types. Sentence: {sentence}. Paraphrase Types: {paraphrase_type}"
 
 
 
 
19
  }
20
  ]
21
  }
22
  return prompt
23
 
 
24
  paraphrase_types = [
25
  "Derivational Changes",
26
  "Inflectional Changes",
@@ -47,11 +53,12 @@ paraphrase_types = [
47
  "Non-paraphrase",
48
  "Addition/Deletion",
49
  "Change of order",
50
- "Semantic-based"
51
  ]
52
 
53
  with gr.Blocks() as demo:
54
- description = gr.Markdown("""
 
55
  ## Paraphrase Type Generator
56
  This demo uses a fine-tuned ChatGPT-3.5 model to generate paraphrases given specific paraphrase types.
57
 
@@ -60,11 +67,12 @@ with gr.Blocks() as demo:
60
  2. Enter a sentence in the text box.
61
  3. Click the "Submit" button or hit enter.
62
  4. The application will generate a paraphrase of the input sentence based on the selected type.
63
- """)
 
64
  chatbot = gr.Chatbot()
65
  types = gr.Dropdown(
66
  paraphrase_types,
67
- value="Syntax-based changes",
68
  multiselect=True,
69
  allow_custom_value=True,
70
  )
@@ -72,13 +80,12 @@ with gr.Blocks() as demo:
72
  submit = gr.Button("Submit")
73
  clear = gr.Button("Clear")
74
 
75
-
76
  def user(user_message, history):
77
  return "", history + [[user_message, None]]
78
 
79
  def generate_paraphrase(user_message, paraphrase_type, history):
80
  history[-1][1] = ""
81
- prompt = create_prompt(history[-1][0], paraphrase_type)
82
  bot_message = openai.ChatCompletion.create(
83
  model="ft:gpt-3.5-turbo-0613:personal::7xbU0xQ2",
84
  messages=prompt["messages"],
@@ -96,6 +103,6 @@ with gr.Blocks() as demo:
96
  generate_paraphrase, [msg, types, chatbot], chatbot
97
  )
98
  clear.click(lambda: None, None, chatbot, queue=False)
99
-
100
  demo.queue()
101
- demo.launch()
 
10
 
11
  openai.api_key = os.environ.get("OPENAI_API_KEY")
12
 
13
+
14
  def create_prompt(sentence, paraphrase_type):
15
  prompt = {
16
  "messages": [
17
  {
18
  "role": "user",
19
+ "content": (
20
+ "Given the following sentence, generate a paraphrase with"
21
+ f" the following types. Sentence: {sentence}. Paraphrase"
22
+ f" Types: {paraphrase_type}"
23
+ ),
24
  }
25
  ]
26
  }
27
  return prompt
28
 
29
+
30
  paraphrase_types = [
31
  "Derivational Changes",
32
  "Inflectional Changes",
 
53
  "Non-paraphrase",
54
  "Addition/Deletion",
55
  "Change of order",
56
+ "Semantic-based",
57
  ]
58
 
59
  with gr.Blocks() as demo:
60
+ description = gr.Markdown(
61
+ """
62
  ## Paraphrase Type Generator
63
  This demo uses a fine-tuned ChatGPT-3.5 model to generate paraphrases given specific paraphrase types.
64
 
 
67
  2. Enter a sentence in the text box.
68
  3. Click the "Submit" button or hit enter.
69
  4. The application will generate a paraphrase of the input sentence based on the selected type.
70
+ """
71
+ )
72
  chatbot = gr.Chatbot()
73
  types = gr.Dropdown(
74
  paraphrase_types,
75
+ value="Modal Verb Changes",
76
  multiselect=True,
77
  allow_custom_value=True,
78
  )
 
80
  submit = gr.Button("Submit")
81
  clear = gr.Button("Clear")
82
 
 
83
  def user(user_message, history):
84
  return "", history + [[user_message, None]]
85
 
86
  def generate_paraphrase(user_message, paraphrase_type, history):
87
  history[-1][1] = ""
88
+ prompt = create_prompt(history[-1][0], paraphrase_type)
89
  bot_message = openai.ChatCompletion.create(
90
  model="ft:gpt-3.5-turbo-0613:personal::7xbU0xQ2",
91
  messages=prompt["messages"],
 
103
  generate_paraphrase, [msg, types, chatbot], chatbot
104
  )
105
  clear.click(lambda: None, None, chatbot, queue=False)
106
+
107
  demo.queue()
108
+ demo.launch()