Skip to main content

Inference from: https://pypi.org/project/gradio-highlightedcode/ Update Custom Package to the Latest Gradio Code (Support for C, C++...) and optimized invocation methods.

Project description

gradio_highlightcode

PyPI - Version

Inference from: https://pypi.org/project/gradio-highlightedcode/ Update Custom Package to the Latest Gradio Code (Support for C, C++...) and optimized invocation methods.

Installation

pip install gradio_highlightcode

Usage

import gradio as gr
from gradio_highlightcode import highlightcode
import time


example = highlightcode().example_value()

initial_value = """
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

"""

with gr.Blocks() as demo:
    code = highlightcode(initial_value, language="c", highlights=[(3, 6, "rgb(255 254 213)")])

if __name__ == "__main__":
    demo.launch()

highlightcode

Initialization

name type default description
value
str | Callable | tuple[str] | None
None Default value to show in the code editor. If callable, the function will be called whenever the app loads to set the initial value of the component.
language
Literal[
        "python",
        "c",
        "cpp",
        "markdown",
        "json",
        "html",
        "css",
        "javascript",
        "typescript",
        "yaml",
        "dockerfile",
        "shell",
        "r",
        "sql",
        "sql-msSQL",
        "sql-mySQL",
        "sql-mariaDB",
        "sql-sqlite",
        "sql-cassandra",
        "sql-plSQL",
        "sql-hive",
        "sql-pgSQL",
        "sql-gql",
        "sql-gpSQL",
        "sql-sparkSQL",
        "sql-esper",
    ]
    | None
None The language to display the code as. Supported languages listed in `gr.Code.languages`.
highlights
list[tuple[int, int, str]] | None
None Specifies the lines to highlight. Use the first number for the starting line, the second for the ending line, and the last parameter for the color.
every
Timer | float | None
None Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
inputs
Component | list[Component] | set[Component] | None
None Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
lines
int
5 None
label
str | None
None The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
interactive
bool | None
None Whether user should be able to enter code or only view it.
show_label
bool | None
None if True, will display label.
container
bool
True If True, will place the component in a container - providing some extra padding around the border.
scale
int | None
None relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
min_width
int
160 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.
visible
bool
True If False, component will be hidden.
elem_id
str | None
None An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
elem_classes
list[str] | str | None
None 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.
render
bool
True If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
key
int | str | None
None if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.

Events

name description
change Triggered when the value of the highlightcode changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.
input This listener is triggered when the user changes the value of the highlightcode.
focus This listener is triggered when the highlightcode is focused.
blur This listener is triggered when the highlightcode is unfocused/blurred.

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, passes the code entered as a str.
  • As input: Should return, expects a str of code or a single-element tuple: (filepath,) with the str path to a file containing the code.
def predict(
    value: str | None
) -> tuple[str] | str | None:
    return value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_highlightcode-0.0.9.tar.gz (385.8 kB view details)

Uploaded Source

Built Distribution

gradio_highlightcode-0.0.9-py3-none-any.whl (336.0 kB view details)

Uploaded Python 3

File details

Details for the file gradio_highlightcode-0.0.9.tar.gz.

File metadata

  • Download URL: gradio_highlightcode-0.0.9.tar.gz
  • Upload date:
  • Size: 385.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for gradio_highlightcode-0.0.9.tar.gz
Algorithm Hash digest
SHA256 f38f8300a2e344a80f8ce92b575684f0b2b89061d6e79c7fbb7bcb9cfd1b4d87
MD5 8645a02167d243714a5b54ca21389850
BLAKE2b-256 a097df3c90dc019757b88a8825b7fbe53b856f4639c2b0f0a3ae0cb8bea77a86

See more details on using hashes here.

File details

Details for the file gradio_highlightcode-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_highlightcode-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2bcf773a140db57438de8cadc4faf02b1ddacf80b9ee3426b566dd7b705781f5
MD5 79ec99de043666ffd90092134d553eaa
BLAKE2b-256 2b2ec316f25780bfdd88ceb602f8c047da62b121de0c5ce311545a397101ef87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page