import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer from huggingface_hub import login import os # Authenticate using token login(token=os.getenv('hf_token')) # Load the model and tokenizer model_name = "mistralai/Mistral-Nemo-Instruct-2407" tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True) model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=True) def generate_response(prompt): inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs, max_length=150, num_return_sequences=1) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response # Define the Gradio interface def chat_function(user_input): return generate_response(user_input) # Launch the Gradio app gr.ChatInterface(fn=chat_function, title="Mistral Chatbot").launch(share=True)