File size: 1,803 Bytes
b308128
937be2f
7f877a9
b308128
8eb0f9a
7eaa7b0
937be2f
 
04fc021
8c245db
edb0bcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8eb0f9a
 
 
 
 
b4af604
8eb0f9a
 
 
ac4f141
edb0bcd
 
 
5e8be56
8c245db
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
42
43
44
45
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
import time

# Load the Vicuna 7B v1.3 LMSys model and tokenizer
model_name = "lmsys/vicuna-7b-v1.3"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

with gr.Blocks() as demo:
    gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")

    with gr.Tab("POS"):
        gr.Markdown(" Description ")

        msg = gr.Textbox(show_label=False, placeholder="Write a prompt and press enter")

        gr.Markdown("Strategy 1 QA")
        with gr.Row():
            vicuna_S1_chatbot_POS = gr.Chatbot(label="vicuna-7b")
            clear = gr.ClearButton([msg, vicuna_S1_chatbot_POS])
        gr.Markdown("Strategy 2 Instruction")
        with gr.Row():
            vicuna_S2_chatbot_POS = gr.Chatbot(label="vicuna-7b")
            clear = gr.ClearButton([msg, vicuna_S2_chatbot_POS])
        gr.Markdown("Strategy 1 Structured Prompting")
        with gr.Row():
            vicuna_S3_chatbot_POS = gr.Chatbot(label="vicuna-7b")
            clear = gr.ClearButton([msg, vicuna_S3_chatbot_POS])

    def respond(message, chat_history):
        input_ids = tokenizer.encode(message, return_tensors="pt")
        output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
        bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
        
        chat_history.append((message, bot_message))
        time.sleep(2)
        return "", chat_history

    msg.submit(respond, [msg, vicuna_S1_chatbot_POS], [msg, vicuna_S1_chatbot_POS])
    msg.submit(respond, [msg, vicuna_S2_chatbot_POS], [msg, vicuna_S2_chatbot_POS])
    msg.submit(respond, [msg, vicuna_S3_chatbot_POS], [msg, vicuna_S3_chatbot_POS])

demo.launch()