Generating interfaces(CLI, Qt GUI, Dash web app) from a Python function.

Overview

oneFace is a Python library for automatically generating multiple interfaces(CLI, GUI, WebGUI) from a callable Python object.

Build Status codecov Documentation Install with PyPi

oneFace is an easy way to create interfaces in Python, just decorate your function and mark the type and range of the arguments:

from oneface import one, Arg

@one
def bmi(name: Arg(str),
        height: Arg(float, [100, 250]) = 160,
        weight: Arg(float, [0, 300]) = 50.0):
    BMI = weight / (height / 100) ** 2
    print(f"Hi {name}. Your BMI is: {BMI}")
    return BMI


# run cli
bmi.cli()
# or run qt_gui
bmi.qt_gui()
# or run dash web app
bmi.dash_app()

These code will generate the following interfaces:

CLI Qt Dash
CLI Qt Dash

Features

  • Generate CLI, Qt GUI, Dash Web app from a python function.
  • Automatically check the type and range of input parameters and pretty print them.
  • Easy extension of parameter types and GUI widgets.

Detail usage see the documentation and pythondig.

Installation

To install oneFace with complete dependency:

$ pip install oneface[all]

Or install with just qt or dash dependency:

$ pip install oneface[qt]  # qt
$ pip install oneface[dash]  # dash
Comments
  • Wrap CLI

    Wrap CLI

    Wrap a CLI program to a GUI/Web interface app.

    Using a .yaml as config to specify the arguments:

    # open_browser_oneface.yaml
    name: open_browser
    
    command: python -m webbrowser {is_tab} {url} 
    
    arguments:
    
      is_tab:
        type: bool
        true_content: "-t"
        false_content: ""
    
      url:
        type: str
    

    Launch the app with:

    $ python -m onface.wrap_cli run open_browser_oneface.yaml qt_gui
    

    It will get a GUI app.

    enhancement 
    opened by Nanguage 1
  • A Thanks Message

    A Thanks Message

    Hello, i am Onur, i am a CTO of a community that develop Blockchain based Decentralized Application Network. This repository have a very good idea. All contributor of this project and me should develop this project and use in the other project. Let's not stop developing.

    Onur Atakan ULUSOY - CTO of Decentra Network Community

    opened by onuratakan 1
  • Implicit Arg convert from Python builtin types

    Implicit Arg convert from Python builtin types

    Allow type annotation with python builtin types, for example:

    from oneface import one, Arg
    
    @one
    def bmi(name: str,
            height: (float, [100, 250]) = 160,
            weight: (float, [0, 300]) = 50.0):
        BMI = weight / (height / 100) ** 2
        print(f"Hi {name}. Your BMI is: {BMI}")
        return BMI
    
    # run cli
    bmi.cli()
    

    Let the annotation automatically convert to Arg when parse the parameters.

    enhancement 
    opened by Nanguage 1
  • Integrate generated qt window to a Qt app.

    Integrate generated qt window to a Qt app.

    import sys
    from oneface.qt import qt_window
    from oneface import one
    from qtpy import QtWidgets
    
    app = QtWidgets.QApplication([])
    
    
    @qt_window
    @one
    def add(a: int, b: int):
        return a + b
    
    @qt_window
    @one
    def mul(a: int, b: int):
        return a * b
    
    
    main_window = QtWidgets.QWidget()
    main_window.setWindowTitle("MyApp")
    main_window.setFixedSize(200, 100)
    layout = QtWidgets.QVBoxLayout(main_window)
    layout.addWidget(QtWidgets.QLabel("Apps:"))
    btn_open_add = QtWidgets.QPushButton("add")
    btn_open_mul = QtWidgets.QPushButton("mul")
    btn_open_add.clicked.connect(add.show)
    btn_open_mul.clicked.connect(mul.show)
    layout.addWidget(btn_open_add)
    layout.addWidget(btn_open_mul)
    main_window.show()
    
    sys.exit(app.exec())
    
    enhancement 
    opened by Nanguage 0
  • Dash: the 'plotly' result_result_type

    Dash: the 'plotly' result_result_type

    Allow render the result with ploty. The wraped function return a plotly figure object:

    from oneface import one, Arg
    import plotly.express as px
    import numpy as np
    
    @one
    def draw_random_points(n: Arg[int, [1, 10000]] = 100):
        x, y = np.random.random(n), np.random.random(n)
        fig = px.scatter(x=x, y=y)
        return fig
    
    draw_random_points.dash_app(
        result_show_type='plotly',
        debug=True)
    
    enhancement 
    opened by Nanguage 0
  • Flask integration of dash app

    Flask integration of dash app

    Embeding the generated dash app as a route of flask server.

    # demo_flask_integrate.py
    from flask import Flask
    from oneface.dash_app import flask_route
    from oneface.core import one
    
    server = Flask("test_dash_app")
    
    @flask_route(server, "/add")
    @one
    def add(a: int, b: int) -> int:
        return a + b
    
    @flask_route(server, "/mul")
    @one
    def mul(a: int, b: int) -> int:
        return a * b
    
    server.run("127.0.0.1", 8088)
    

    Run this will launch a flask server support run multiple dash app from different route.

    References:

    • https://blog.finxter.com/dash-flask/
    enhancement 
    opened by Nanguage 0
  • Define custom dash commpont to support complex input type.

    Define custom dash commpont to support complex input type.

    For example:

    from oneface import one, Arg
    from oneface.dash_app import App, InputItem
    from dash import dcc, html
    
    class Person:
        def __init__(self, name, age):
            self.name = name
            self.age = age
    
    
    def check_person_type(val, tp):
        return (
            isinstance(val, tp) and
            isinstance(val.name, str) and
            isinstance(val.age, int)
        )
    
    Arg.register_type_check(Person, check_person_type)
    Arg.register_range_check(Person, lambda val, range: range[0] <= val.age <= range[1])
    
    class PersonInputItem(InputItem):
        def get_input(self):
            if self.default:
                default_val = f"Person('{self.default.name}', {self.default.age})"
            else:
                default_val = ""
            return dcc.Input(
                placeholder="example: Person('age', 20)",
                type="text",
                value=default_val,
                style={
                    "width": "100%",
                    "height": "40px",
                    "margin": "5px",
                    "font-size": "20px",
                }
            )
    
    
    App.register_widget(Person, PersonInputItem)
    App.register_type_convert(Person, lambda s: eval(s))
    
    
    @one
    def print_person(person: Arg(Person, [0, 100]) = Person("Tom", 10)):
        print(f"{person.name} is {person.age} years old.")
    
    
    print_person.dash_app()
    
    

    This code using the serialized input Person, how to define a "Composite components" in dash to support Person input? Just like in Qt:

    image

    question 
    opened by Nanguage 0
Releases(0.1.9)
Simple implementation of Self Organizing Maps (SOMs) with rectangular and hexagonal grid topologies

py-self-organizing-map Simple implementation of Self Organizing Maps (SOMs) with rectangular and hexagonal grid topologies. A SOM is a simple unsuperv

Jonas Grebe 1 Feb 10, 2022
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Altair 8k Jan 05, 2023
Learning Convolutional Neural Networks with Interactive Visualization.

CNN Explainer An interactive visualization system designed to help non-experts learn about Convolutional Neural Networks (CNNs) For more information,

Polo Club of Data Science 6.3k Jan 01, 2023
HW_02 Data visualisation task

HW_02 Data visualisation and Matplotlib practice Instructions for HW_02 Idea for data analysis As I was brainstorming ideas and running through databa

9 Dec 13, 2022
Interactive plotting for Pandas using Vega-Lite

pdvega: Vega-Lite plotting for Pandas Dataframes pdvega is a library that allows you to quickly create interactive Vega-Lite plots from Pandas datafra

Altair 342 Oct 26, 2022
A central task in drug discovery is searching, screening, and organizing large chemical databases

A central task in drug discovery is searching, screening, and organizing large chemical databases. Here, we implement clustering on molecular similarity. We support multiple methods to provide a inte

NVIDIA Corporation 124 Jan 07, 2023
HW 02 for CS40 - matplotlib practice

HW 02 for CS40 - matplotlib practice project instructions https://github.com/mikeizbicki/cmc-csci040/tree/2021fall/hw_02 Drake Lyric Analysis Bar Char

13 Oct 27, 2021
The visual framework is designed on the idea of module and implemented by mixin method

Visual Framework The visual framework is designed on the idea of module and implemented by mixin method. Its biggest feature is the mixins module whic

LEFTeyes 9 Sep 19, 2022
Python toolkit for defining+simulating+visualizing+analyzing attractors, dynamical systems, iterated function systems, roulette curves, and more

Attractors A small module that provides functions and classes for very efficient simulation and rendering of iterated function systems; dynamical syst

1 Aug 04, 2021
This is my favourite function - the Rastrigin function.

This is my favourite function - the Rastrigin function. What sparked my curiosity and interest in the function was its complexity in terms of many local optimum points, which makes it particularly in

1 Dec 27, 2021
PyPassword is a simple follow up to PyPassphrase

PyPassword PyPassword is a simple follow up to PyPassphrase. After finishing that project it occured to me that while some may wish to use that option

Scotty 2 Jan 22, 2022
Rubrix is a free and open-source tool for exploring and iterating on data for artificial intelligence projects.

Open-source tool for exploring, labeling, and monitoring data for AI projects

Recognai 1.5k Jan 07, 2023
3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)

PyVista Deployment Build Status Metrics Citation License Community 3D plotting and mesh analysis through a streamlined interface for the Visualization

PyVista 1.6k Jan 08, 2023
Calendar heatmaps from Pandas time series data

Note: See MarvinT/calmap for the maintained version of the project. That is also the version that gets published to PyPI and it has received several f

Martijn Vermaat 195 Dec 22, 2022
:art: Diagram as Code for prototyping cloud system architectures

Diagrams Diagram as Code. Diagrams lets you draw the cloud system architecture in Python code. It was born for prototyping a new system architecture d

MinJae Kwon 27.5k Dec 30, 2022
Print matplotlib colors

mplcolors Tired of searching "matplotlib colors" every week/day/hour? This simple script displays them all conveniently right in your terminal emulato

Brandon Barker 32 Dec 13, 2022
Extensible, parallel implementations of t-SNE

openTSNE openTSNE is a modular Python implementation of t-Distributed Stochasitc Neighbor Embedding (t-SNE) [1], a popular dimensionality-reduction al

Pavlin Poličar 1.1k Jan 03, 2023
Scientific measurement library for instruments, experiments, and live-plotting

PyMeasure scientific package PyMeasure makes scientific measurements easy to set up and run. The package contains a repository of instrument classes a

PyMeasure 445 Jan 04, 2023
This is a Cross-Platform Plot Manager for Chia Plotting that is simple, easy-to-use, and reliable.

Swar's Chia Plot Manager A plot manager for Chia plotting: https://www.chia.net/ Development Version: v0.0.1 This is a cross-platform Chia Plot Manage

Swar Patel 1.3k Dec 13, 2022
Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax.

PyDexter Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax. Setup $ pip install PyDexter

D3xter 31 Mar 06, 2021