File size: 885 Bytes
34d67cb
 
26e6a51
e5a5a0d
26e6a51
 
e5a5a0d
34d67cb
 
 
26e6a51
 
34d67cb
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)