コード例 #1
0
              border_style="green",
              title="Опции:",
              caption="t.me/matazimov_official")
table.add_column("№")
table.add_column("Описание")
table.add_row("1", "Добавить друзей со стен групп/страниц")
table.add_row("2", "Добавить друзей с раздела рекоменд.")
table.add_row("3", "Принять [bold yellow]новые[/bold yellow] заявки в друзья")
table.add_row("4", "Принять [bold red]все[/bold red] заявки в друзья")
table.add_row("5", "Отписаться от [bold red]всех[/bold red] исходящих заявок")
table.add_row("6", "Удалить неактивных друзей")
table.add_row("7", "Удалить невидимых друзей")
table.add_row("8", "Удалить собачек из друзей")
table.add_row("9", "Удалить [bold red]всех[/bold red] друзей")
table.add_row("0", "Помощь")
table.caption_style = "bold cyan"

console = Console()
console.print(table)

print("")
vid = input(f"({first_name} {last_name}) Выберите опцию: ")

if vid == "1":
    import handlers.friends_add_from_wall
elif vid == "2":
    import handlers.friends_add_from_recommended_section
elif vid == "3":
    import handlers.request_accept.new
elif vid == "4":
    import handlers.request_accept.all
コード例 #2
0
    def summary(
        self,
        x: tp.Optional[tp.Any] = None,
        depth: int = 2,
        tablefmt: str = "fancy_grid",
        return_repr: bool = False,
        initialize: bool = False,
        eval_shape: bool = True,
        **tablulate_kwargs,
    ) -> tp.Optional[str]:
        """
        Prints a summary of the network.
        Arguments:
            x: A sample of inputs to the network.
            depth: The level number of nested level which will be showed.
                Information about summaries from modules deeper than `depth`
                will be aggregated together.
            tablefmt: A string representing the style of the table generated by
                `tabulate`. See
                [python-tabulate](https://github.com/astanin/python-tabulate)
                for more options.
            tablulate_kwargs: Additional keyword arguments passed to `tabulate`.
                See [python-tabulate](https://github.com/astanin/python-tabulate)
                for more options.
        """

        if x is None:
            x = {}

        entries: tp.List[types.SummaryTableEntry]
        states = self.states.copy() if self.run_eagerly else self.states

        method = (self.call_summary_step
                  if self.run_eagerly else self.call_summary_step_jit)

        if eval_shape:
            entries = jax.eval_shape(self.call_summary_step, x, states)
        else:
            entries = method(x, states)

        total_entry = entries[-1]
        entries = entries[:-1]

        depth_groups: tp.Dict[
            str, tp.List[types.SummaryTableEntry]] = toolz.groupby(
                lambda entry: "/".join(entry.path.split("/")[:depth]), entries)

        entries = [
            utils.get_grouped_entry(entry, depth_groups) for entry in entries
            if entry.path in depth_groups
        ]

        main_table = Table(
            show_header=True,
            show_lines=True,
            show_footer=True,
            # box=rich.box.HORIZONTALS,
        )

        main_table.add_column("Layer")
        main_table.add_column("Outputs Shape")
        main_table.add_column("Trainable\nParameters")
        main_table.add_column("Non-trainable\nParameters")

        rows: tp.List[tp.List[str]] = []

        rows.append(["Inputs", utils.format_output(x), "", ""])

        for entry in entries:
            rows.append([
                f"{entry.path}{{pad}}  " + (f"[dim]{entry.module_type_name}[/]"
                                            if entry.module_type_name else ""),
                utils.format_output(entry.output_value),
                f"[green]{entry.trainable_params_count:,}[/]{{pad}}    {utils.format_size(entry.trainable_params_size)}"
                if entry.trainable_params_count > 0 else "",
                f"[green]{entry.non_trainable_params_count:,}[/]{{pad}}    {utils.format_size(entry.non_trainable_params_size)}"
                if entry.non_trainable_params_count > 0 else "",
            ])

        # global summaries
        params_count = total_entry.trainable_params_count
        params_size = total_entry.trainable_params_size
        states_count = total_entry.non_trainable_params_count
        states_size = total_entry.non_trainable_params_size
        total_count = params_count + states_count
        total_size = params_size + states_size

        rows.append([
            "",
            "Total",
            (f"[green]{params_count:,}[/]{{pad}}    {utils.format_size(params_size)}"
             if params_count > 0 else ""),
            (f"[green]{states_count:,}[/]{{pad}}    {utils.format_size(states_size)}"
             if states_count > 0 else ""),
        ])

        # add padding
        for col in range(4):
            max_length = max(
                len(line.split("{pad}")[0]) for row in rows
                for line in row[col].split("\n"))

            for row in rows:
                row[col] = "\n".join(
                    line.format(
                        pad=" " *
                        (max_length - len(line.rstrip().split("{pad}")[0])))
                    for line in row[col].rstrip().split("\n"))

        for row in rows[:-1]:
            main_table.add_row(*row)

        main_table.columns[1].footer = Text.from_markup(rows[-1][1],
                                                        justify="right")
        main_table.columns[2].footer = rows[-1][2]
        main_table.columns[3].footer = rows[-1][3]
        main_table.caption_style = "bold"
        main_table.caption = (
            "\nTotal Parameters: " +
            f"[green]{total_count:,}[/]   {utils.format_size(total_size)}"
            if total_count > 0 else "")

        summary = "\n" + utils.get_table_repr(main_table)

        print(summary)

        if return_repr:
            return summary