Spaces:
Runtime error
Runtime error
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer | |
| import gradio as gr | |
| model_id = "linjc16/Panacea-7B-Chat" | |
| # Load tokenizer and model | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.float16, | |
| device_map="auto", | |
| trust_remote_code=True | |
| ) | |
| streamer = TextStreamer(tokenizer) | |
| # Chat function | |
| def chat(message, history=[]): | |
| prompt = message | |
| input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device) | |
| with torch.no_grad(): | |
| output = model.generate( | |
| input_ids, | |
| max_new_tokens=512, | |
| do_sample=True, | |
| temperature=0.7, | |
| top_p=0.9 | |
| ) | |
| reply = tokenizer.decode(output[0], skip_special_tokens=True) | |
| return reply | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=chat, | |
| inputs=gr.Textbox(lines=2, placeholder="Type your message here..."), | |
| outputs="text", | |
| title="Panacea-7B-Chat" | |
| ) | |
| iface.launch() | |