Spaces:
Runtime error
Runtime error
GilbertKiwanuka commited on
Commit ·
34e4a78
1
Parent(s): 830d742
third step
Browse filesFiles changed (2)
- app.py+28-4
- requirements.txt+4
1234567import gradio as grdef greet(name):return "Hello " + name + "!!"demo = gr.Interface(fn=greet, inputs="text", outputs="text")demo.launch()12345678910111213141516171819202122232425262728293031import gradio as grfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch# 1) Load modeltokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf",torch_dtype=torch.float16,device_map="auto")# 2) Chat functiondef chat(history, user_input):history = history or []history.append(("You", user_input))inputs = tokenizer([f"{u}: {m}" for u,m in history],return_tensors="pt", truncation=True, padding=True).to(model.device)out = model.generate(**inputs, max_new_tokens=128)reply = tokenizer.decode(out[0], skip_special_tokens=True)history.append(("Bot", reply))return history, ""# 3) Gradio UIwith gr.Blocks() as demo:chatbot = gr.Chatbot()userbox = gr.Textbox(placeholder="Type a message and press Enter")userbox.submit(chat, [chatbot, userbox], [chatbot, userbox])demo.launch()
1234gradiotransformerstorchbitsandbytes
app.py+28-4
requirements.txt+4