File size: 1,035 Bytes
82c6fa1
 
d97af2c
 
82c6fa1
d97af2c
82c6fa1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d97af2c
 
82c6fa1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()