import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer # Load the model and tokenizer model_name = "google/flan-t5-xxl" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) # Define the chat function def chat(message): # Encode the user's message inputs = tokenizer.encode(message, return_tensors="pt") # Generate a response from the model outputs = model.generate(inputs, max_length=1024, pad_token_id=tokenizer.eos_token_id) response = tokenizer.decode(outputs[0], skip_special_tokens=True) # Return the response return response # Set up the Gradio interface block = gr.Blocks(css=".gradio-container {background-color: lightgray}") with block: with gr.Row(): gr.Markdown("