rkoushikroy2 commited on
Commit
a597063
β€’
1 Parent(s): 9a97606

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +7 -14
  2. helper_functions.py +12 -0
app.py CHANGED
@@ -4,25 +4,15 @@ from helper_functions import *
4
  with gr.Blocks() as app:
5
  gr.Markdown('# Prompt Generator for FundedNext')
6
  session_data = gr.State([{"current_system_prompt": ""}])
7
-
8
- def get_prompt(user_message, session_data):
9
- if(user_message == ""):
10
- return_message = "Please enter your message"
11
- return return_message
12
- pre_text = session_data[0]["current_system_prompt"]
13
- return_message = pre_text + "\n\n" + get_context(user_message)
14
- return return_message
15
- def set_pre_text(system_prompt, session_data):
16
- session_data[0]["current_system_prompt"] = system_prompt
17
- return session_data
18
 
19
  with gr.Tab("Generate Prompt"):
20
  user_message = gr.Textbox(label = "Enter your message")
21
- prompt = gr.Textbox(label="Generated Prompt", interactive=True, lines=20)
22
  with gr.Tab("Edit System Prompt"):
23
  system_prompt = gr.Textbox(
24
  label="System Prompt", interactive=True, lines=15
25
- )
 
26
  gr.Markdown("## System Prompt Examples")
27
  gr.Examples(
28
  examples = [[pre_text]],
@@ -32,7 +22,10 @@ with gr.Blocks() as app:
32
  user_message.submit(
33
  fn = get_prompt, inputs = [user_message, session_data], outputs = prompt
34
  ).then(lambda:"", inputs=None, outputs=user_message, queue=False)
35
- system_prompt.change(
 
 
 
36
  fn = set_pre_text, inputs = [system_prompt, session_data], outputs = session_data, queue=False
37
  )
38
 
 
4
  with gr.Blocks() as app:
5
  gr.Markdown('# Prompt Generator for FundedNext')
6
  session_data = gr.State([{"current_system_prompt": ""}])
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  with gr.Tab("Generate Prompt"):
9
  user_message = gr.Textbox(label = "Enter your message")
10
+ prompt = gr.Textbox(label="Generated Prompt", interactive=True, lines=20).style(show_copy_button=True)
11
  with gr.Tab("Edit System Prompt"):
12
  system_prompt = gr.Textbox(
13
  label="System Prompt", interactive=True, lines=15
14
+ ).style(show_copy_button=True)
15
+ save_s_p = gr.Button("Save System Prompt")
16
  gr.Markdown("## System Prompt Examples")
17
  gr.Examples(
18
  examples = [[pre_text]],
 
22
  user_message.submit(
23
  fn = get_prompt, inputs = [user_message, session_data], outputs = prompt
24
  ).then(lambda:"", inputs=None, outputs=user_message, queue=False)
25
+ save_s_p.click(
26
+ fn = set_pre_text, inputs = [system_prompt, session_data], outputs = session_data, queue=False
27
+ )
28
+ system_prompt.submit(
29
  fn = set_pre_text, inputs = [system_prompt, session_data], outputs = session_data, queue=False
30
  )
31
 
helper_functions.py CHANGED
@@ -44,3 +44,15 @@ def get_context(query):
44
  My question is: β€œ{query}”
45
  """
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  My question is: β€œ{query}”
45
  """
46
 
47
+
48
+ def get_prompt(user_message, session_data):
49
+ if(user_message == ""):
50
+ return_message = "Please enter your message"
51
+ return return_message
52
+ pre_text = session_data[0]["current_system_prompt"]
53
+ return_message = pre_text + "\n\n" + get_context(user_message)
54
+ return return_message
55
+ def set_pre_text(system_prompt, session_data):
56
+ session_data[0]["current_system_prompt"] = system_prompt
57
+ return session_data
58
+