2023-03-15 16:33:26 +01:00
|
|
|
from pathlib import Path
|
|
|
|
|
2023-01-22 04:02:46 +01:00
|
|
|
import gradio as gr
|
|
|
|
|
|
|
|
refresh_symbol = '\U0001f504' # 🔄
|
|
|
|
|
2023-03-15 16:33:26 +01:00
|
|
|
with open(Path(__file__).resolve().parent / '../css/main.css', 'r') as f:
|
|
|
|
css = f.read()
|
|
|
|
with open(Path(__file__).resolve().parent / '../css/chat.css', 'r') as f:
|
|
|
|
chat_css = f.read()
|
|
|
|
with open(Path(__file__).resolve().parent / '../css/main.js', 'r') as f:
|
2023-03-15 17:24:54 +01:00
|
|
|
main_js = f.read()
|
|
|
|
with open(Path(__file__).resolve().parent / '../css/chat.js', 'r') as f:
|
|
|
|
chat_js = f.read()
|
2023-03-15 16:01:32 +01:00
|
|
|
|
2023-04-07 05:15:45 +02:00
|
|
|
|
2023-01-22 04:02:46 +01:00
|
|
|
class ToolButton(gr.Button, gr.components.FormComponent):
|
|
|
|
"""Small button with single emoji as text, fits inside gradio forms"""
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(variant="tool", **kwargs)
|
|
|
|
|
|
|
|
def get_block_name(self):
|
|
|
|
return "button"
|
|
|
|
|
2023-04-07 05:15:45 +02:00
|
|
|
|
2023-01-22 04:02:46 +01:00
|
|
|
def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
|
|
|
|
def refresh():
|
|
|
|
refresh_method()
|
|
|
|
args = refreshed_args() if callable(refreshed_args) else refreshed_args
|
|
|
|
|
|
|
|
for k, v in args.items():
|
|
|
|
setattr(refresh_component, k, v)
|
|
|
|
|
|
|
|
return gr.update(**(args or {}))
|
|
|
|
|
|
|
|
refresh_button = ToolButton(value=refresh_symbol, elem_id=elem_id)
|
|
|
|
refresh_button.click(
|
|
|
|
fn=refresh,
|
|
|
|
inputs=[],
|
|
|
|
outputs=[refresh_component]
|
|
|
|
)
|
|
|
|
return refresh_button
|