vpcom commited on
Commit
116d146
1 Parent(s): 3842ab5

fix: initialized the super model

Browse files
Files changed (1) hide show
  1. app.py +144 -0
app.py CHANGED
@@ -231,6 +231,86 @@ p {direction: rtl; white-space: pre-line;}
231
  """
232
 
233
  class Chatbot(gr.Chatbot):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  def _preprocess_chat_messages(
235
  self, chat_message: str | dict | None
236
  ) -> str | tuple[str] | tuple[str, str] | None:
@@ -350,6 +430,70 @@ textbox_whoareu = gr.Textbox(
350
  )
351
 
352
  class ChatInterface(gr.ChatInterface):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  async def _submit_fn(
354
  self,
355
  message: str,
 
231
  """
232
 
233
  class Chatbot(gr.Chatbot):
234
+ def __init__(
235
+ self,
236
+ value: list[list[str | tuple[str] | tuple[str | Path, str] | None]]
237
+ | Callable
238
+ | None = None,
239
+ color_map: dict[str, str] | None = None,
240
+ *,
241
+ label: str | None = None,
242
+ every: float | None = None,
243
+ show_label: bool | None = None,
244
+ container: bool = True,
245
+ scale: int | None = None,
246
+ min_width: int = 160,
247
+ visible: bool = True,
248
+ elem_id: str | None = None,
249
+ elem_classes: list[str] | str | None = None,
250
+ height: int | None = None,
251
+ latex_delimiters: list[dict[str, str | bool]] | None = None,
252
+ rtl: bool = False,
253
+ show_share_button: bool | None = None,
254
+ show_copy_button: bool = False,
255
+ avatar_images: tuple[str | Path | None, str | Path | None] | None = None,
256
+ sanitize_html: bool = True,
257
+ render_markdown: bool = True,
258
+ bubble_full_width: bool = True,
259
+ line_breaks: bool = True,
260
+ layout: Literal["panel", "bubble"] | None = None,
261
+ **kwargs,
262
+ ):
263
+ """
264
+ Parameters:
265
+ value: Default value to show in chatbot. If callable, the function will be called whenever the app loads to set the initial value of the component.
266
+ color_map: This parameter is deprecated.
267
+ label: component name in interface.
268
+ every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
269
+ show_label: if True, will display label.
270
+ container: If True, will place the component in a container - providing some extra padding around the border.
271
+ scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
272
+ min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
273
+ visible: If False, component will be hidden.
274
+ elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
275
+ elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
276
+ height: height of the component in pixels.
277
+ latex_delimiters: A list of dicts of the form {"left": open delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass in an empty list to disable LaTeX rendering. For more information, see the [KaTeX documentation](https://katex.org/docs/autorender.html).
278
+ rtl: If True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right.
279
+ show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.
280
+ show_copy_button: If True, will show a copy button for each chatbot message.
281
+ avatar_images: Tuple of two avatar image paths or URLs for user and bot (in that order). Pass None for either the user or bot image to skip. Must be within the working directory of the Gradio app or an external URL.
282
+ sanitize_html: If False, will disable HTML sanitization for chatbot messages. This is not recommended, as it can lead to security vulnerabilities.
283
+ render_markdown: If False, will disable Markdown rendering for chatbot messages.
284
+ bubble_full_width: If False, the chat bubble will fit to the content of the message. If True (default), the chat bubble will be the full width of the component.
285
+ line_breaks: If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies if `render_markdown` is True.
286
+ layout: If "panel", will display the chatbot in a llm style layout. If "bubble", will display the chatbot with message bubbles, with the user and bot messages on alterating sides. Will default to "bubble".
287
+ """
288
+ super().__init__(
289
+ value = value,
290
+ color_map = color_map,
291
+ label = label,
292
+ every = every,
293
+ show_label = show_label,
294
+ container = container,
295
+ scale = scale,
296
+ min_width = min_width,
297
+ visible = visible,
298
+ elem_id = elem_id,
299
+ elem_classes = elem_classes,
300
+ height = height,
301
+ latex_delimiters = latex_delimiters,
302
+ rtl = rtl,
303
+ show_share_button = show_share_button,
304
+ show_copy_button = show_copy_button,
305
+ avatar_images = avatar_images,
306
+ sanitize_html = sanitize_html,
307
+ render_markdown = render_markdown,
308
+ bubble_full_width = bubble_full_width,
309
+ line_breaks = line_breaks,
310
+ layout = layout,
311
+ kwargs=**kwargs,
312
+ )
313
+
314
  def _preprocess_chat_messages(
315
  self, chat_message: str | dict | None
316
  ) -> str | tuple[str] | tuple[str, str] | None:
 
430
  )
431
 
432
  class ChatInterface(gr.ChatInterface):
433
+ def __init__(
434
+ self,
435
+ fn: Callable,
436
+ *,
437
+ chatbot: Chatbot | None = None,
438
+ textbox: Textbox | None = None,
439
+ additional_inputs: str | IOComponent | list[str | IOComponent] | None = None,
440
+ additional_inputs_accordion_name: str = "Additional Inputs",
441
+ examples: list[str] | None = None,
442
+ cache_examples: bool | None = None,
443
+ title: str | None = None,
444
+ description: str | None = None,
445
+ theme: Theme | str | None = None,
446
+ css: str | None = None,
447
+ analytics_enabled: bool | None = None,
448
+ submit_btn: str | None | Button = "Submit",
449
+ stop_btn: str | None | Button = "Stop",
450
+ retry_btn: str | None | Button = "🔄 Retry",
451
+ undo_btn: str | None | Button = "↩️ Undo",
452
+ clear_btn: str | None | Button = "🗑️ Clear",
453
+ autofocus: bool = True,
454
+ ):
455
+ """
456
+ Parameters:
457
+ fn: the function to wrap the chat interface around. Should accept two parameters: a string input message and list of two-element lists of the form [[user_message, bot_message], ...] representing the chat history, and return a string response. See the Chatbot documentation for more information on the chat history format.
458
+ chatbot: an instance of the gr.Chatbot component to use for the chat interface, if you would like to customize the chatbot properties. If not provided, a default gr.Chatbot component will be created.
459
+ textbox: an instance of the gr.Textbox component to use for the chat interface, if you would like to customize the textbox properties. If not provided, a default gr.Textbox component will be created.
460
+ additional_inputs: an instance or list of instances of gradio components (or their string shortcuts) to use as additional inputs to the chatbot. If components are not already rendered in a surrounding Blocks, then the components will be displayed under the chatbot, in an accordion.
461
+ additional_inputs_accordion_name: the label of the accordion to use for additional inputs, only used if additional_inputs is provided.
462
+ examples: sample inputs for the function; if provided, appear below the chatbot and can be clicked to populate the chatbot input.
463
+ cache_examples: If True, caches examples in the server for fast runtime in examples. The default option in HuggingFace Spaces is True. The default option elsewhere is False.
464
+ title: a title for the interface; if provided, appears above chatbot in large font. Also used as the tab title when opened in a browser window.
465
+ description: a description for the interface; if provided, appears above the chatbot and beneath the title in regular font. Accepts Markdown and HTML content.
466
+ theme: Theme to use, loaded from gradio.themes.
467
+ css: custom css or path to custom css file to use with interface.
468
+ analytics_enabled: Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable if defined, or default to True.
469
+ submit_btn: Text to display on the submit button. If None, no button will be displayed. If a Button object, that button will be used.
470
+ stop_btn: Text to display on the stop button, which replaces the submit_btn when the submit_btn or retry_btn is clicked and response is streaming. Clicking on the stop_btn will halt the chatbot response. If set to None, stop button functionality does not appear in the chatbot. If a Button object, that button will be used as the stop button.
471
+ retry_btn: Text to display on the retry button. If None, no button will be displayed. If a Button object, that button will be used.
472
+ undo_btn: Text to display on the delete last button. If None, no button will be displayed. If a Button object, that button will be used.
473
+ clear_btn: Text to display on the clear button. If None, no button will be displayed. If a Button object, that button will be used.
474
+ autofocus: If True, autofocuses to the textbox when the page loads.
475
+ """
476
+ super().__init__(
477
+ fn = fn,
478
+ chatbot = chatbot,
479
+ textbox= textbox,
480
+ additional_inputs = additional_inputs,
481
+ additional_inputs_accordion_name = additional_inputs_accordion_name,
482
+ examples = examples,
483
+ cache_examples = cache_examples,
484
+ title = title,
485
+ description = description,
486
+ theme = theme,
487
+ css = css,
488
+ analytics_enabled = analytics_enabled,
489
+ submit_btn = submit_btn,
490
+ stop_btn = stop_btn,
491
+ retry_btn = retry_btn,
492
+ undo_btn = undo_btn,
493
+ clear_btn = clear_btn,
494
+ autofocus = autofocus,
495
+ )
496
+
497
  async def _submit_fn(
498
  self,
499
  message: str,