research14 commited on
Commit
a7472ee
·
1 Parent(s): d366b82
Files changed (1) hide show
  1. app.py +26 -22
app.py CHANGED
@@ -15,26 +15,24 @@ with gr.Blocks() as demo:
15
  gr.Markdown(" Description ")
16
 
17
  with gr.Row():
18
- prompt = 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 = gr.Chatbot(label="vicuna-7b", live=True)
24
- llama_chatbot1 = gr.Chatbot(label="llama-7b", live=False)
25
- gpt_chatbot1 = gr.Chatbot(label="gpt-3.5", live=False)
26
  gr.Markdown("Strategy 2 Instruction")
27
  with gr.Row():
28
- vicuna_chatbot2 = gr.Chatbot(label="vicuna-7b", live=True)
29
- llama_chatbot2 = gr.Chatbot(label="llama-7b", live=False)
30
- gpt_chatbot2 = gr.Chatbot(label="gpt-3.5", live=False)
31
  gr.Markdown("Strategy 3 Structured Prompting")
32
  with gr.Row():
33
- vicuna_chatbot3 = gr.Chatbot(label="vicuna-7b", live=True)
34
- llama_chatbot3 = gr.Chatbot(label="llama-7b", live=False)
35
- gpt_chatbot3 = gr.Chatbot(label="gpt-3.5", live=False)
36
-
37
- clear = gr.ClearButton([prompt, vicuna_chatbot1])
38
 
39
  with gr.Tab("Chunk"):
40
  gr.Markdown(" Description 2 ")
@@ -62,20 +60,26 @@ with gr.Blocks() as demo:
62
  clear = gr.ClearButton([prompt_chunk, vicuna_chatbot1_chunk])
63
 
64
  # Define the function for generating responses
65
- def generate_response(model, tokenizer, prompt):
66
- inputs = tokenizer(prompt, return_tensors="pt")
67
- outputs = model.generate(**inputs, max_length=500, pad_token_id=tokenizer.eos_token_id)
68
- response = tokenizer.decode(outputs[0])
69
  return response
70
 
71
  # Define the Gradio interface
72
- def chatbot_interface(prompt):
73
- vicuna_response = generate_response(model, tokenizer, prompt)
74
- # llama_response = generate_response(llama_model, llama_tokenizer, prompt)
 
 
 
 
 
 
75
 
76
- return {"Vicuna-7B": vicuna_response}
 
 
77
 
78
- # Replace the old respond function with the new general function for Vicuna
79
- prompt.submit(chatbot_interface, [prompt, vicuna_chatbot1, vicuna_chatbot1_chunk])
80
 
81
  demo.launch()
 
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 ")
 
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(prompt_POS):
71
+ vicuna_response_POS = generate_response(prompt_POS)
72
+ # Add responses from other chatbots if needed
73
+ return {"Vicuna-7B": vicuna_response_POS}
74
+
75
+ def chatbot_interface_Chunk(prompt_chunk):
76
+ vicuna_response_chunk = generate_response(prompt_chunk)
77
+ # Add responses from other chatbots if needed
78
+ return {"Vicuna-7B": vicuna_response_chunk}
79
 
80
+ # Connect the interfaces to the functions
81
+ send_button_POS.click(chatbot_interface_POS, [prompt_POS, vicuna_chatbot1_POS])
82
+ send_button_Chunk.click(chatbot_interface_Chunk, [prompt_chunk, vicuna_chatbot1_chunk])
83
 
 
 
84
 
85
  demo.launch()