srl-lite / app.py
SamerKharboush's picture
Upload 13 files
214d428 verified
import gradio as gr
import sqlite3
import uuid
from datetime import datetime
import gradio as gr
import pandas as pd
import sqlite3
from filter import filter_data, sdg_column_mapping
from tar import sdg_indicators_mapping, sdg_input_mapping, sdg_formulas_mapping
from deep import filter_and_store_data, data , gradio_app, user_latest_data, create_database ,add_indicator, variable_outputs, get_new_ind, user_late_data, update_indicator_dropdown , sign_in, sign_up, fetch_all_data , calculate_indicator
from gradio import utils, themes
from chat2 import demo
import subprocess
import time
# Define a custom HTML component with an iframe to display the Dash app
html_component = gr.HTML("<iframe src='http://localhost:55007' width=100% height='1200'></iframe>")
# Create a Gradio interface with the HTML component
iplot = gr.Interface(
fn=None, # Set fn to None since we don't need a function
inputs=None,
outputs=html_component,
live=True
)
iface = gr.Interface(
fn=sign_in,
inputs=[
gr.Textbox(label="Username"),
gr.Textbox(label="Password", type="password"),
],
outputs="text",
title="Sign In",
theme='xiaobaiyuan/theme_brief'
)
iface2 = gr.Interface(
fn=sign_up,
inputs=[
gr.Textbox(label="Username"),
gr.Textbox(label="Password", type="password"),
gr.Textbox(label="Email", type='email'),
],
outputs="text",
title="Sign Up",
theme='xiaobaiyuan/theme_brief'
)
create_database()
max_indicators = 15
with gr.Blocks(visible=True, title="SRL Data Collector", theme='xiaobaiyuan/theme_brief') as ifa:
with gr.Row(variant='panel'):
username = gr.Textbox(label="Username",visible=False)
username2 = gr.Label(label='Username',value=user_late_data())
country_dropdown = gr.Dropdown(choices=list(data['Name'].unique()), type="value", label="Country")
sdg_dropdown = gr.Dropdown(choices=list(sdg_column_mapping.keys()), type="value", label="SDG Number")
initial_sdg = sdg_dropdown.choices[0]
with gr.Column(variant='panel'):
indicator_dropdown = gr.Dropdown(choices=[update_indicator_dropdown(initial_sdg)], allow_custom_value=True,multiselect=True, interactive=True,type="value", label="Indicator")
sdg_dropdown.change(update_indicator_dropdown, sdg_dropdown, indicator_dropdown)
with gr.Column(variant='panel'):
rows= []
for i in range(max_indicators):
row = add_indicator(i)
row.visible = False
rows.append(row)
sdg_dropdown.change(variable_outputs, sdg_dropdown, rows)
with gr.Row(variant='panel'):
save_button = gr.Button("Save")
output = gr.HTML(label="Filtered Data")
save_button.click(fn=gradio_app, inputs=[username2, country_dropdown, sdg_dropdown, output], outputs=output)
app = gr.Blocks(theme='xiaobaiyuan/theme_brief')
with gr.Blocks(theme='xiaobaiyuan/theme_brief') as calo:
show = gr.Button("Show me my data!")
with gr.Row():
user = gr.Label(label="Username")
countr = gr.Label(label="Country Name")
sdg = gr.Label(label="SDG Number")
with gr.Row():
indi = gr.Label(label="Indicator")
name = gr.Label(label="Names")
inp1 = gr.Label(label="Input First")
with gr.Row():
res = gr.HTML(label="Result")
show.click(fn=fetch_all_data, inputs=None, outputs=[user, countr, sdg, res, indi, name, inp1])
calculate = gr.Button("Calculate")
calculate.click(fn=calculate_indicator, inputs=[user, countr, sdg], outputs=res)
with app:
gr.Markdown("""
# SRL App
""")
tab1 = gr.Tab("Sign In")
tab2 = gr.Tab("Sign Up")
tab3 = gr.Tab("Data Collect")
tab4 = gr.Tab("Data Processing")
tab5 = gr.Tab("SRL Dash")
tab6 = gr.Tab("AI Chat")
with tab1:
iface.render()
with tab2:
iface2.render()
with tab3:
if ifa.visible:
ifa.render()
with tab4:
calo.render()
with tab5:
iplot.render()
with tab6:
demo.render()
app.launch(server_name="0.0.0.0", share=True)