#!/usr/bin/env python # coding: utf-8 import pandas as pd import random from IPython.display import display # import ipywidgets as widgets import gradio as gr from pipeline import getEngine from dotenv import load_dotenv from config import getParams load_dotenv() params = getParams('config.yaml') art_descr = params['art_descr'] with open('style/app.css', 'r') as css_f: css = css_f.read() # load existing data from file (in widget: drag-drop your file?) df = pd.read_parquet( params['stock_price_fn'] ).interpolate(method="linear", axis=1) tickers_desc_all = pd.read_parquet(params['tickers_descriptors_fn']) tickers_desc_prefilter = tickers_desc_all.loc[df.columns] sectors = list(tickers_desc_prefilter["sector"].unique()[0:10]) engines = ["corrinv", "lof", "geo (BETA)"] if_inputs = [ gr.Textbox(lines=1, label="Keywords search", placeholder="Keywords Here..."), gr.Checkbox(label="Exact match", value=False), gr.Dropdown(sectors, label="Sectors picker"), gr.Dropdown(engines, label="Detection engine"), gr.Slider(0, 100, label="Relevance threshold (percentile)", value=15), gr.Slider(0, 1, step=0.01, label="Correlation threshold (0-1)", value=0.875), gr.Slider(0, 1, step=0.1, label="Cutoff point (0-1)", value=0.5), gr.Checkbox( label="Generate natural language outcome (EXPERIMENTAL)", value=False ), ] if_outputs = [ gr.DataFrame( label=( "Top matching tickers, sorted by descending relevance [FOR DEMO" " PURPOSES ONLY]" ), headers=["symbol", "keywords", "relevance", "industry"], ), gr.Textbox(label="Matching tickers count (search space size)"), gr.Textbox(label="Anomaly detection outcome"), gr.Image(label="Anomaly plot"), gr.Textbox(label="Human-readable description (EXPERIMENTAL)"), ] demo = gr.Interface( css = css, title = "Batonics AB | Anomalous events detection pipeline", description = art_descr, fn = getEngine, # pick pipeline, use chosen engine inputs = if_inputs, outputs = if_outputs, examples = params['examples'], cache_examples = False, allow_flagging = "auto", ) if __name__ == "__main__": # demo.launch(auth_message="Contact matteo@batonics.com to get access.") demo.launch( #auth=("batonics", "batonicsdemo22"), server_name = '0.0.0.0', show_api = False, )