import argparse import gradio as gr import torch from model import IntentPredictModel from transformers import (T5Tokenizer, GPT2Tokenizer, GPT2Config, GPT2LMHeadModel) from diffusers import StableDiffusionPipeline from chatbot import Chat def main(args): # Intent Prediction print("Loading Intent Prediction Classifier...") ## tokenizer intent_predict_tokenizer = T5Tokenizer.from_pretrained(args.intent_predict_model_name, truncation_side='left') intent_predict_tokenizer.add_special_tokens({'sep_token': '[SEP]'}) # model intent_predict_model = IntentPredictModel(pretrained_model_name_or_path=args.intent_predict_model_name, num_classes=2) intent_predict_model.load_state_dict(torch.load(args.intent_predict_model_weights_path, map_location=args.device)) print("Intent Prediction Classifier loading completed.") # Textual Dialogue Response Generator print("Loading Textual Dialogue Response Generator...") ## tokenizer text_dialog_tokenizer = GPT2Tokenizer.from_pretrained(args.text_dialog_model_name, truncation_side='left') text_dialog_tokenizer.add_tokens(['[UTT]', '[DST]']) print(len(text_dialog_tokenizer)) # config text_dialog_config = GPT2Config.from_pretrained(args.text_dialog_model_name) if len(text_dialog_tokenizer) > text_dialog_config.vocab_size: text_dialog_config.vocab_size = len(text_dialog_tokenizer) # load model weights text_dialog_model = GPT2LMHeadModel.from_pretrained(args.text_dialog_model_weights_path, config=text_dialog_config) print("Textual Dialogue Response Generator loading completed.") # Text-to-Image Translator print("Loading Text-to-Image Translator...") text2image_model = StableDiffusionPipeline.from_pretrained(args.text2image_model_weights_path, torch_dtype=torch.float32) print("Text-to-Image Translator loading completed.") chat = Chat(intent_predict_model, intent_predict_tokenizer, text_dialog_model, text_dialog_tokenizer, text2image_model, args.device) title = """