CoolFace
Apppublic

erpsarang/AI-ChatBot

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
1likes
app.py47 linesDownload Raw Back to root
1from transformers import AutoModelForCausalLM, AutoTokenizer2import gradio as gr3import torch4 5 6title = "erpsarang's bigdata AI ChatBot"7description = "bigdata GPT"8examples = [["How are you?"]]9 10 11tokenizer = AutoTokenizer.from_pretrained("erpsarang/Llama-3-Open-Ko-8B-Instruct-erpsarang")12model = AutoModelForCausalLM.from_pretrained("erpsarang/Llama-3-Open-Ko-8B-Instruct-erpsarang")13 14 15def predict(input, history=[]):16    # tokenize the new input sentence17    new_user_input_ids = tokenizer.encode(18        input + tokenizer.eos_token, return_tensors="pt"19    )20 21    # append the new user input tokens to the chat history22    bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)23 24    # generate a response25    history = model.generate(26        bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id27    ).tolist()28 29    # convert the tokens to text, and then split the responses into lines30    response = tokenizer.decode(history[0]).split("<|endoftext|>")31    # print('decoded_response-->>'+str(response))32    response = [33        (response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)34    ]  # convert to tuples of list35    # print('response-->>'+str(response))36    return response, history37 38 39gr.Interface(40    fn=predict,41    title=title,42    description=description,43    examples=examples,44    inputs=["text", "state"],45    outputs=["chatbot", "state"],46    theme="finlaymacklon/boxy_violet",47).launch()