File size: 1,081 Bytes
6637280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import random
import time
from ctransformers import AutoModelForCausalLM

params = {
        "max_new_tokens":512,
        "stop":["<end>" ,"<|endoftext|>"],
        "temperature":0.7,
        "top_p":0.8,
        "stream":True,
        "batch_size": 8}


llm = AutoModelForCausalLM.from_pretrained("Lajonbot/WizardLM-13B-V1.2-PL-lora_GGML", model_type="llama")

with gr.Blocks() as demo:
    chatbot = gr.Chatbot()
    msg = gr.Textbox()
    clear = gr.Button("Clear")

    def user(user_message, history):
        return "", history + [[user_message, None]]

    def bot(history):
        stream = llm(prompt =  f"Jesteś AI assystentem. Odpowiadaj po polski. <user>: {history}. <assistant>:", **params)
        history[-1][1] = ""
        for character in stream:
            history[-1][1] += character
            time.sleep(0.005)
            yield history

    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )
    clear.click(lambda: None, None, chatbot, queue=False)
    
demo.queue()
demo.launch()