ak3ra commited on
Commit
52a64e1
1 Parent(s): 660cea6

minor changes to the chatui

Browse files
__pycache__/app.cpython-311.pyc ADDED
Binary file (7.91 kB). View file
 
app.py CHANGED
@@ -19,6 +19,9 @@ def get_rag_pipeline(study_name):
19
 
20
 
21
  def chat_function(message, history, study_name, prompt_type):
 
 
 
22
  rag = get_rag_pipeline(study_name)
23
  prompt = (
24
  highlight_prompt
@@ -34,30 +37,54 @@ def get_study_info(study_name):
34
  if study_file:
35
  with open(study_file, "r") as f:
36
  data = json.load(f)
37
- return f"**Number of documents:** {len(data)}\n\n**First document title:** {data[0]['title']}"
38
  else:
39
  return "Invalid study name"
40
 
41
 
42
- with gr.Blocks(css="#chatbot {height: 600px; overflow-y: auto;}") as demo:
43
- gr.Markdown("# RAG Pipeline Demo")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  with gr.Row():
46
- with gr.Column(scale=3):
47
- chatbot = gr.Chatbot(elem_id="chatbot")
48
  with gr.Row():
49
  msg = gr.Textbox(
50
- show_label=False, placeholder="Enter your message here...", scale=4
 
 
 
 
51
  )
52
  send_btn = gr.Button("Send", scale=1)
 
 
 
 
53
 
54
  with gr.Column(scale=1):
 
55
  study_dropdown = gr.Dropdown(
56
  choices=list(STUDY_FILES.keys()),
57
  label="Select Study",
58
  value=list(STUDY_FILES.keys())[0],
59
  )
60
- study_info = gr.Markdown()
 
61
  prompt_type = gr.Radio(
62
  ["Default", "Highlight", "Evidence-based"],
63
  label="Prompt Type",
@@ -65,12 +92,14 @@ with gr.Blocks(css="#chatbot {height: 600px; overflow-y: auto;}") as demo:
65
  )
66
  clear = gr.Button("Clear Chat")
67
 
68
- gr.Examples(examples=sample_questions[list(STUDY_FILES.keys())[0]], inputs=msg)
69
-
70
  def user(user_message, history):
 
 
71
  return "", history + [[user_message, None]]
72
 
73
  def bot(history, study_name, prompt_type):
 
 
74
  user_message = history[-1][0]
75
  bot_message = chat_function(user_message, history, study_name, prompt_type)
76
  history[-1][1] = bot_message
@@ -85,10 +114,15 @@ with gr.Blocks(css="#chatbot {height: 600px; overflow-y: auto;}") as demo:
85
  clear.click(lambda: None, None, chatbot, queue=False)
86
 
87
  study_dropdown.change(
88
- fn=get_study_info,
89
  inputs=study_dropdown,
90
- outputs=study_info,
91
  )
92
 
 
 
 
 
 
93
  if __name__ == "__main__":
94
  demo.launch(share=True, debug=True)
 
19
 
20
 
21
  def chat_function(message, history, study_name, prompt_type):
22
+ if not message.strip():
23
+ return "Please enter a valid query."
24
+
25
  rag = get_rag_pipeline(study_name)
26
  prompt = (
27
  highlight_prompt
 
37
  if study_file:
38
  with open(study_file, "r") as f:
39
  data = json.load(f)
40
+ return f"Number of documents: {len(data)}\nFirst document title: {data[0]['title']}"
41
  else:
42
  return "Invalid study name"
43
 
44
 
45
+ def update_interface(study_name):
46
+ study_info = get_study_info(study_name)
47
+ questions = sample_questions.get(study_name, [])[:3]
48
+ return (
49
+ study_info,
50
+ *[gr.update(visible=True, value=q) for q in questions],
51
+ *[gr.update(visible=False) for _ in range(3 - len(questions))],
52
+ )
53
+
54
+
55
+ def set_question(question):
56
+ return question
57
+
58
+
59
+ with gr.Blocks() as demo:
60
+ gr.Markdown("# ACRES RAG Platform")
61
 
62
  with gr.Row():
63
+ with gr.Column(scale=2):
64
+ chatbot = gr.Chatbot(elem_id="chatbot", show_label=False, height=400)
65
  with gr.Row():
66
  msg = gr.Textbox(
67
+ show_label=False,
68
+ placeholder="Type your message here...",
69
+ scale=4,
70
+ lines=1,
71
+ autofocus=True,
72
  )
73
  send_btn = gr.Button("Send", scale=1)
74
+ with gr.Accordion("Sample Questions", open=False):
75
+ sample_btn1 = gr.Button("Sample Question 1", visible=False)
76
+ sample_btn2 = gr.Button("Sample Question 2", visible=False)
77
+ sample_btn3 = gr.Button("Sample Question 3", visible=False)
78
 
79
  with gr.Column(scale=1):
80
+ gr.Markdown("### Study Information")
81
  study_dropdown = gr.Dropdown(
82
  choices=list(STUDY_FILES.keys()),
83
  label="Select Study",
84
  value=list(STUDY_FILES.keys())[0],
85
  )
86
+ study_info = gr.Textbox(label="Study Details", lines=4)
87
+ gr.Markdown("### Settings")
88
  prompt_type = gr.Radio(
89
  ["Default", "Highlight", "Evidence-based"],
90
  label="Prompt Type",
 
92
  )
93
  clear = gr.Button("Clear Chat")
94
 
 
 
95
  def user(user_message, history):
96
+ if not user_message.strip():
97
+ return "", history # Return unchanged if the message is empty
98
  return "", history + [[user_message, None]]
99
 
100
  def bot(history, study_name, prompt_type):
101
+ if not history:
102
+ return history
103
  user_message = history[-1][0]
104
  bot_message = chat_function(user_message, history, study_name, prompt_type)
105
  history[-1][1] = bot_message
 
114
  clear.click(lambda: None, None, chatbot, queue=False)
115
 
116
  study_dropdown.change(
117
+ fn=update_interface,
118
  inputs=study_dropdown,
119
+ outputs=[study_info, sample_btn1, sample_btn2, sample_btn3],
120
  )
121
 
122
+ sample_btn1.click(set_question, inputs=[sample_btn1], outputs=[msg])
123
+ sample_btn2.click(set_question, inputs=[sample_btn2], outputs=[msg])
124
+ sample_btn3.click(set_question, inputs=[sample_btn3], outputs=[msg])
125
+
126
+
127
  if __name__ == "__main__":
128
  demo.launch(share=True, debug=True)
rag/__pycache__/rag_pipeline.cpython-311.pyc CHANGED
Binary files a/rag/__pycache__/rag_pipeline.cpython-311.pyc and b/rag/__pycache__/rag_pipeline.cpython-311.pyc differ
 
rag/rag_pipeline.py CHANGED
@@ -29,6 +29,7 @@ class RAGPipeline:
29
  f"Title: {doc_data['title']}\n"
30
  f"Abstract: {doc_data['abstract']}\n"
31
  f"Authors: {', '.join(doc_data['authors'])}\n"
 
32
  )
33
 
34
  metadata = {
 
29
  f"Title: {doc_data['title']}\n"
30
  f"Abstract: {doc_data['abstract']}\n"
31
  f"Authors: {', '.join(doc_data['authors'])}\n"
32
+ # f"full_text: {doc_data['full_text']}"
33
  )
34
 
35
  metadata = {