import os from typing import Optional, Tuple import gradio as gr import argparse import datetime import pickle #import whisper import dotenv import sys from io import StringIO import re dotenv.load_dotenv() from langchain.callbacks import get_openai_callback import hydra from omegaconf import DictConfig, open_dict, OmegaConf class ChatbotAgentGradio(): def __init__( self, config_name ): config = OmegaConf.load(f'./config/{config_name}.yaml') self.chatbot = hydra.utils.instantiate(config.model, _convert_="partial") def chat(self, inp: str, history: Optional[Tuple[str, str]], ): """Method for integration with gradio Chatbot""" print("\n==== date/time: " + str(datetime.datetime.now()) + " ====") print("inp: " + inp) history = history or [] output = self.chatbot.run(inp) history.append((inp, output)) return history, history#, "" def update_foo(self, widget, state): if widget: state = widget return state def launch_app(self): block = gr.Blocks(css=".gradio-container {background-color: lightgray}") with block: instance = gr.State() show_chain_state = gr.State(False) with gr.Row(): gr.Markdown("