wop commited on
Commit
0eacc14
1 Parent(s): 5195c78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -11
app.py CHANGED
@@ -18,16 +18,16 @@ def save_database(database):
18
  with open(DATABASE_PATH, "w") as file:
19
  json.dump(database, file)
20
 
21
- def format_prompt(message, history):
22
  # Format prompt according to the new template
23
- prompt = "SYSTEM: You are a helpful assistant, with no access to external functions.\n<|endofsystem|>\n"
24
  for user_prompt, bot_response in history:
25
  prompt += f"USER: {user_prompt}\n\n\nASSISTANT: {bot_response}<|endoftext|>\n"
26
  prompt += f"USER: {message}\n\n\nASSISTANT:"
27
  return prompt
28
 
29
  def generate(
30
- prompt, history, temperature=0.9, max_new_tokens=4096, top_p=0.9, repetition_penalty=1.2,
31
  ):
32
  database = load_database() # Load the database
33
  temperature = float(temperature)
@@ -47,17 +47,62 @@ def generate(
47
 
48
  yield response_text
49
 
50
- css = """
51
- #mkd {
52
- height: 500px;
53
- overflow: auto;
54
- border: 1px solid #ccc;
55
- }
56
  """
57
 
58
- with gr.Blocks(css=css) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  gr.ChatInterface(
60
  generate,
 
61
  )
62
 
63
- demo.launch(debug=True)
 
18
  with open(DATABASE_PATH, "w") as file:
19
  json.dump(database, file)
20
 
21
+ def format_prompt(message, system, history):
22
  # Format prompt according to the new template
23
+ prompt = f"SYSTEM: {system}\n<|endofsystem|>\n"
24
  for user_prompt, bot_response in history:
25
  prompt += f"USER: {user_prompt}\n\n\nASSISTANT: {bot_response}<|endoftext|>\n"
26
  prompt += f"USER: {message}\n\n\nASSISTANT:"
27
  return prompt
28
 
29
  def generate(
30
+ prompt, system, history, temperature=0.9, max_new_tokens=4096, top_p=0.9, repetition_penalty=1.2,
31
  ):
32
  database = load_database() # Load the database
33
  temperature = float(temperature)
 
47
 
48
  yield response_text
49
 
50
+ customCSS = """
51
+ #component-7 { # this is the default element ID of the chat component
52
+ height: 1600px; # adjust the height as needed
53
+ flex-grow: 4;
54
+ }
 
55
  """
56
 
57
+ additional_inputs=[
58
+ gr.TextBox(
59
+ label="System prompt",
60
+ value="You are a helpful assistant, with no access to external functions.",
61
+ info="System prompt",
62
+ interactive=True,
63
+ ),
64
+ gr.Slider(
65
+ label="Temperature",
66
+ value=0.9,
67
+ minimum=0.0,
68
+ maximum=1.0,
69
+ step=0.05,
70
+ interactive=True,
71
+ info="Higher values produce more diverse outputs",
72
+ ),
73
+ gr.Slider(
74
+ label="Max new tokens",
75
+ value=1024,
76
+ minimum=64,
77
+ maximum=4096,
78
+ step=64,
79
+ interactive=True,
80
+ info="The maximum numbers of new tokens",
81
+ ),
82
+ gr.Slider(
83
+ label="Top-p (nucleus sampling)",
84
+ value=0.90,
85
+ minimum=0.0,
86
+ maximum=1,
87
+ step=0.05,
88
+ interactive=True,
89
+ info="Higher values sample more low-probability tokens",
90
+ ),
91
+ gr.Slider(
92
+ label="Repetition penalty",
93
+ value=1.2,
94
+ minimum=1.0,
95
+ maximum=2.0,
96
+ step=0.05,
97
+ interactive=True,
98
+ info="Penalize repeated tokens",
99
+ )
100
+ ]
101
+
102
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
103
  gr.ChatInterface(
104
  generate,
105
+ additional_inputs=additional_inputs,
106
  )
107
 
108
+ demo.queue().launch(debug=True)