research14 commited on
Commit
8eb0f9a
·
1 Parent(s): 94f7425
Files changed (1) hide show
  1. app.py +16 -80
app.py CHANGED
@@ -1,89 +1,25 @@
1
  import gradio as gr
2
- import random
3
- import time
4
- from transformers import AutoModelForCausalLM, AutoTokenizer
5
 
6
- # Load Vicuna 7B model and tokenizer
7
  model_name = "lmsys/vicuna-7b-v1.3"
8
- model = AutoModelForCausalLM.from_pretrained(model_name)
9
- tokenizer = AutoTokenizer.from_pretrained(model_name)
10
 
11
  with gr.Blocks() as demo:
12
- gr.Markdown("# LLM Evaluator With Linguistic Scrutiny")
13
-
14
- with gr.Tab("POS"):
15
- gr.Markdown(" Description ")
16
-
17
- with gr.Row():
18
- prompt_POS = gr.Textbox(show_label=False, placeholder="Enter prompt")
19
- send_button_POS = gr.Button("Send", scale=0)
20
-
21
- gr.Markdown("Strategy 1 QA")
22
- with gr.Row():
23
- vicuna_chatbot1_POS = gr.Chatbot(label="vicuna-7b", live=True)
24
- llama_chatbot1_POS = gr.Chatbot(label="llama-7b", live=False)
25
- gpt_chatbot1_POS = gr.Chatbot(label="gpt-3.5", live=False)
26
- gr.Markdown("Strategy 2 Instruction")
27
- with gr.Row():
28
- vicuna_chatbot2_POS = gr.Chatbot(label="vicuna-7b", live=True)
29
- llama_chatbot2_POS = gr.Chatbot(label="llama-7b", live=False)
30
- gpt_chatbot2_POS = gr.Chatbot(label="gpt-3.5", live=False)
31
- gr.Markdown("Strategy 3 Structured Prompting")
32
- with gr.Row():
33
- vicuna_chatbot3_POS = gr.Chatbot(label="vicuna-7b", live=True)
34
- llama_chatbot3_POS = gr.Chatbot(label="llama-7b", live=False)
35
- gpt_chatbot3_POS = gr.Chatbot(label="gpt-3.5", live=False)
36
-
37
- with gr.Tab("Chunk"):
38
- gr.Markdown(" Description 2 ")
39
-
40
- with gr.Row():
41
- prompt_chunk = gr.Textbox(show_label=False, placeholder="Enter prompt")
42
- send_button_Chunk = gr.Button("Send", scale=0)
43
-
44
- gr.Markdown("Strategy 1 QA")
45
- with gr.Row():
46
- vicuna_chatbot1_chunk = gr.Chatbot(label="vicuna-7b", live=True)
47
- llama_chatbot1_chunk = gr.Chatbot(label="llama-7b", live=False)
48
- gpt_chatbot1_chunk = gr.Chatbot(label="gpt-3.5", live=False)
49
- gr.Markdown("Strategy 2 Instruction")
50
- with gr.Row():
51
- vicuna_chatbot2_chunk = gr.Chatbot(label="vicuna-7b", live=True)
52
- llama_chatbot2_chunk = gr.Chatbot(label="llama-7b", live=False)
53
- gpt_chatbot2_chunk = gr.Chatbot(label="gpt-3.5", live=False)
54
- gr.Markdown("Strategy 3 Structured Prompting")
55
- with gr.Row():
56
- vicuna_chatbot3_chunk = gr.Chatbot(label="vicuna-7b", live=True)
57
- llama_chatbot3_chunk = gr.Chatbot(label="llama-7b", live=False)
58
- gpt_chatbot3_chunk = gr.Chatbot(label="gpt-3.5", live=False)
59
 
60
- clear = gr.ClearButton([prompt_chunk, vicuna_chatbot1_chunk])
61
-
62
- # Define the function for generating responses
63
- def generate_response(prompt):
64
- input_ids = tokenizer.encode(prompt, return_tensors="pt")
65
- output_ids = model.generate(input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id)
66
- response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
67
- return response
68
-
69
- # Define the Gradio interface
70
- def chatbot_interface_POS(input_dict):
71
- prompt_POS = input_dict["prompt_POS"]
72
- vicuna_response_POS = generate_response(prompt_POS)
73
- # Add responses from other chatbots if needed
74
- return {"Vicuna-7B": vicuna_response_POS}
75
-
76
- def chatbot_interface_Chunk(input_dict):
77
- prompt_chunk = input_dict["prompt_chunk"]
78
- vicuna_response_chunk = generate_response(prompt_chunk)
79
- # Add responses from other chatbots if needed
80
- return {"Vicuna-7B": vicuna_response_chunk}
81
-
82
- # Connect the interfaces to the functions
83
- send_button_POS.click(chatbot_interface_POS, inputs=[prompt_POS, vicuna_chatbot1_POS])
84
- send_button_Chunk.click(chatbot_interface_Chunk, inputs=[prompt_chunk, vicuna_chatbot1_chunk])
85
-
86
-
87
 
 
88
 
89
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
 
 
3
 
4
+ # Load the Vicuna 7B v1.3 LMSys model and tokenizer
5
  model_name = "lmsys/vicuna-7b-v1.3"
6
+ model = GPT2LMHeadModel.from_pretrained(model_name)
7
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
8
 
9
  with gr.Blocks() as demo:
10
+ chatbot = gr.Chatbot()
11
+ msg = gr.Textbox()
12
+ clear = gr.ClearButton([msg, chatbot])
13
+
14
+ def respond(message, chat_history):
15
+ input_ids = tokenizer.encode(message, return_tensors="pt")
16
+ output_ids = model.generate(input_ids, max_length=50, num_beams=5, no_repeat_ngram_size=2)
17
+ bot_message = tokenizer.decode(output_ids[0], skip_special_tokens=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
+ chat_history.append((message, bot_message))
20
+ time.sleep(2)
21
+ return "", chat_history
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
24
 
25
  demo.launch()