ruggsea commited on
Commit
d24bdab
·
1 Parent(s): 9e9cac6
Files changed (1) hide show
  1. app.py +70 -53
app.py CHANGED
@@ -108,51 +108,64 @@ def create_demo() -> gr.Blocks:
108
 
109
  gr.Markdown("<br>")
110
 
111
- gr.ChatInterface(
112
- fn=generate,
113
- additional_inputs=[
114
- gr.Textbox(
115
- label="System prompt",
116
- lines=6,
117
- value="You are a knowledgeable philosophy professor using the Stanford Encyclopedia of Philosophy as your knowledge base. Provide clear, accurate responses using markdown formatting. Focus on philosophical concepts and maintain academic rigor while being accessible. Always cite relevant philosophers and concepts."
118
- ),
119
- gr.Slider(
120
- label="Max new tokens",
121
- minimum=1,
122
- maximum=MAX_MAX_NEW_TOKENS,
123
- step=1,
124
- value=DEFAULT_MAX_NEW_TOKENS,
125
- ),
126
- gr.Slider(
127
- label="Temperature",
128
- minimum=0.1,
129
- maximum=4.0,
130
- step=0.1,
131
- value=0.7,
132
- ),
133
- gr.Slider(
134
- label="Top-p (nucleus sampling)",
135
- minimum=0.05,
136
- maximum=1.0,
137
- step=0.05,
138
- value=0.9,
139
- ),
140
- gr.Slider(
141
- label="Top-k",
142
- minimum=1,
143
- maximum=1000,
144
- step=1,
145
- value=50,
146
- ),
147
- gr.Slider(
148
- label="Repetition penalty",
149
- minimum=1.0,
150
- maximum=2.0,
151
- step=0.05,
152
- value=1.1,
153
- ),
154
- ],
155
- stop_btn=None,
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  examples=[
157
  ["What is the trolley problem and what are its main ethical implications?"],
158
  ["Can you explain Plato's Theory of Forms?"],
@@ -160,14 +173,18 @@ def create_demo() -> gr.Blocks:
160
  ["How does Kant's Categorical Imperative work?"],
161
  ["What is the problem of consciousness in philosophy of mind?"],
162
  ],
163
- chatbot=gr.Chatbot(
164
- show_label=False,
165
- avatar_images=(None, None),
166
- ),
167
- autofocus=True,
168
- retry_btn=None,
169
- undo_btn=None,
170
- clear_btn=None,
 
 
 
 
171
  )
172
 
173
  gr.Markdown(LICENSE)
 
108
 
109
  gr.Markdown("<br>")
110
 
111
+ chatbot = gr.Chatbot(
112
+ show_label=False,
113
+ avatar_images=(None, None),
114
+ )
115
+
116
+ with gr.Row():
117
+ msg = gr.Textbox(
118
+ scale=4,
119
+ show_label=False,
120
+ placeholder="Enter text and press enter",
121
+ container=False,
122
+ )
123
+ submit = gr.Button("Submit", scale=1, variant="primary")
124
+
125
+ system_prompt = gr.Textbox(
126
+ label="System prompt",
127
+ lines=6,
128
+ value="You are a knowledgeable philosophy professor using the Stanford Encyclopedia of Philosophy as your knowledge base. Provide clear, accurate responses using markdown formatting. Focus on philosophical concepts and maintain academic rigor while being accessible. Always cite relevant philosophers and concepts."
129
+ )
130
+
131
+ with gr.Accordion("Generation Parameters", open=False):
132
+ max_new_tokens = gr.Slider(
133
+ label="Max new tokens",
134
+ minimum=1,
135
+ maximum=MAX_MAX_NEW_TOKENS,
136
+ step=1,
137
+ value=DEFAULT_MAX_NEW_TOKENS,
138
+ )
139
+ temperature = gr.Slider(
140
+ label="Temperature",
141
+ minimum=0.1,
142
+ maximum=4.0,
143
+ step=0.1,
144
+ value=0.7,
145
+ )
146
+ top_p = gr.Slider(
147
+ label="Top-p (nucleus sampling)",
148
+ minimum=0.05,
149
+ maximum=1.0,
150
+ step=0.05,
151
+ value=0.9,
152
+ )
153
+ top_k = gr.Slider(
154
+ label="Top-k",
155
+ minimum=1,
156
+ maximum=1000,
157
+ step=1,
158
+ value=50,
159
+ )
160
+ repetition_penalty = gr.Slider(
161
+ label="Repetition penalty",
162
+ minimum=1.0,
163
+ maximum=2.0,
164
+ step=0.05,
165
+ value=1.1,
166
+ )
167
+
168
+ gr.Examples(
169
  examples=[
170
  ["What is the trolley problem and what are its main ethical implications?"],
171
  ["Can you explain Plato's Theory of Forms?"],
 
173
  ["How does Kant's Categorical Imperative work?"],
174
  ["What is the problem of consciousness in philosophy of mind?"],
175
  ],
176
+ inputs=msg,
177
+ )
178
+
179
+ msg.submit(
180
+ generate,
181
+ [msg, chatbot, system_prompt, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
182
+ [chatbot],
183
+ )
184
+ submit.click(
185
+ generate,
186
+ [msg, chatbot, system_prompt, max_new_tokens, temperature, top_p, top_k, repetition_penalty],
187
+ [chatbot],
188
  )
189
 
190
  gr.Markdown(LICENSE)