buildinqq commited on
Commit
5055394
·
verified ·
1 Parent(s): d480247

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +410 -215
app.py CHANGED
@@ -1,203 +1,227 @@
1
  import os
2
- token_r=os.environ['token_r']
3
- token_r=os.environ['token_r_nt']
4
- token_w=os.environ['token_w']
5
- token_w_feedback=os.environ['token_w_feedback']
6
- es_cloud_id=os.environ['es_cloud_id']
7
- feedback_store=os.environ['feedback_store']
8
- es_password=os.environ['es_password']
9
-
10
- from llama_index.core import Settings
11
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
12
- from llama_index.vector_stores.elasticsearch import ElasticsearchStore
13
  from llama_index.core.query_engine import CitationQueryEngine
14
  from llama_index.core import VectorStoreIndex
 
 
 
15
  from llama_index.core.postprocessor import SimilarityPostprocessor
16
 
17
- import torch
18
- from transformers import AutoTokenizer
19
- from llama_index.llms.huggingface import HuggingFaceLLM
20
- from transformers import BitsAndBytesConfig
21
- import asyncio
22
-
23
- import re
24
- import pandas as pd
25
-
26
- import gradio as gr
27
- import logging
28
-
29
- #Enable logging to see what's happening behind the scenes
30
- logging.basicConfig(level=logging.INFO)
31
-
32
- model_name = "meta-llama/Meta-Llama-3-8B-Instruct"
33
-
34
- tokenizer = AutoTokenizer.from_pretrained(
35
- model_name,
36
- token=token_r,
37
- )
38
-
39
- stopping_ids = [
40
- tokenizer.eos_token_id,
41
- tokenizer.convert_tokens_to_ids("<|eot_id|>"),
 
 
42
  ]
43
 
44
- quantization_config = BitsAndBytesConfig(
45
- load_in_4bit=True,
46
- bnb_4bit_compute_dtype=torch.float16,
47
- bnb_4bit_quant_type="nf4",
48
- bnb_4bit_use_double_quant=True,
49
  )
50
 
 
 
 
51
 
52
- # Get the model
53
- llm = HuggingFaceLLM(
54
- model_name=model_name,
55
- tokenizer_name=model_name,
56
- model_kwargs={
57
- "token": token_r,
58
- "quantization_config": quantization_config
59
- },
60
- context_window=8191,
61
- max_new_tokens=2048,
62
- generate_kwargs={
63
- # "do_sample": True,
64
- # "temperature": 0.1,
65
- # "top_p": 0.9,
66
- 'repetition_penalty': 1.175,
67
- # 'early_stopping': True
68
- },
69
- stopping_ids=stopping_ids,
70
- )
71
-
72
- # bge embedding model
73
- embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
74
- Settings.embed_model = embed_model
75
-
76
- # Llama-3-8B-Instruct model
77
  Settings.llm = llm
 
78
 
79
- # Get data from Elasticsearch
80
-
81
- es_vector_store = ElasticsearchStore(
82
- index_name="train_criteria_index",
83
- es_cloud_id=es_cloud_id,
84
- es_user="elastic",
85
- es_password=es_password,
86
- )
87
 
88
- index_es = VectorStoreIndex.from_vector_store(es_vector_store)
89
 
90
- query_engine_get_study = CitationQueryEngine.from_args(
91
- index_es,
92
- similarity_top_k=5,
 
93
  citation_chunk_size=2048,
94
- node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.8)],
95
- use_async=True,
96
  verbose=True,
97
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- # # Regex patterns for output cleaning
100
- # inclusion_pattern = r'Inclusion Criteria(.*?)(?=\*\*Exclusion Criteria)'
101
- # exclusion_pattern = r'Exclusion Criteria(.*?)(?=\*\*Reference Papers)'
102
- # reference_pattern = r'Reference Papers(.*)'
103
-
104
- # # Flags for multiline and dotall
105
- # flags = re.MULTILINE | re.DOTALL
106
-
107
- # # Function to clean text
108
- # def clean_text(text):
109
- # # Remove asterisks
110
- # cleaned = re.sub(r'\*', '', text)
111
- # # # Remove extra whitespace
112
- # # cleaned = re.sub(r'\s+', ' ', cleaned)
113
- # # Remove leading/trailing whitespace
114
- # return cleaned.strip()
115
-
116
- async def get_prompt(text):
117
- studies_response = await query_engine_get_study.aquery(f"""
118
- Based on the provided instructions and clinical trial information, delimited by ### Clinical Trial Information, which study has similar study information?
119
- Ensure the studies are relevant and have similar study information. Prioritize the following topics when finding related studies:
120
- 1. Conditions
121
- 2. Intervention/Treatment
122
- 3. Study Objectives
123
- 4. Study Design and Phases
124
-
125
- ### Clinical Trial Information:
126
- {text}
127
- """)
128
-
129
- study_ref=[]
130
- metadata_list = []
131
- for source in studies_response.source_nodes:
132
- ref = source.node.get_text()
133
- study_ref.append(ref)
134
- meta_data = source.node.get_metadata_str()
135
- metadata_list.append(meta_data)
136
-
137
- # return stream_
138
- criteria_response = await llm.acomplete(f"""
139
- Based on the provided instructions and clinical trial information, generate the eligibility criteria for the study.
140
-
141
- ## Instruction:
142
- As a clinical researcher, generate new eligibility criteria for clinical research based on the given clinical trial information.
143
- Please analyze the given clinical trial information, delimited by ### Clinical Trial Information, and analyze the information from the following papers, delimited by ### Related data, for more precise new eligibility criteria generation. Do not copy the ### Related data.
144
- Please provide me NCT IDs and study names using information from the following papers, delimited by ### Reference Papers.
145
- Please follow the pattern of the output, delimited by ### Pattern of the output.
146
- Ensure the criteria are clear, specific, and suitable for a clinical research information.
147
- Do not generate any other topic, explain text, python code, or any step of thought except the pattern of the output.
148
-
149
- --------------------------------------------------
150
- ### Clinical Trial Information
151
- {text}
152
- --------------------------------------------------
153
- ### Related data
154
- {study_ref}
155
- --------------------------------------------------
156
- ### Reference Papers
157
- {metadata_list}
158
- --------------------------------------------------
159
- ### Pattern of the output
160
- Inclusion Criteria
161
- 1.
162
- 2.
163
-
164
- Exclusion Criteria
165
- 1.
166
- 2.
167
-
168
- Reference Papers
169
- 1. NCT ID:
170
- Study Name:
171
- 2. NCT ID:
172
- Study Name:
173
- 3. NCT ID:
174
- Study Name:
175
-
176
- """
177
  )
178
-
179
- # # Extract and clean data
180
- # inclusion_criteria = clean_text(re.search(inclusion_pattern, text, flags).group(1))
181
- # exclusion_criteria = clean_text(re.search(exclusion_pattern, text, flags).group(1))
182
- # reference_papers = clean_text(re.search(reference_pattern, text, flags).group(1))
183
-
184
- # # Combine all sections into one formatted string
185
- # criteria_response = f"""Inclusion Criteria:
186
- # {inclusion_criteria}
187
-
188
- # Exclusion Criteria:
189
- # {exclusion_criteria}
190
-
191
- # Reference Papers:
192
- # {reference_papers}"""
193
-
194
- # return criteria_response
195
-
196
- return criteria_response.text
197
- # for chunk in criteria_response:
198
- # yield chunk
199
 
 
200
 
 
201
  place_holder = f"""Study Objectives
202
  The purpose of this study is to evaluate the safety, tolerance and efficacy of Liposomal Paclitaxel With Nedaplatin as First-line in patients with Advanced or Recurrent Esophageal Carcinoma
203
 
@@ -216,46 +240,217 @@ TREATMENT Allocation: NA
216
  Interventional Model: SINGLE_GROUP Masking: NONE
217
  """
218
 
219
- prefilled_value = """Study Objectives
220
- [Brief Summary and/or Detailed Description]
 
 
 
221
 
222
- Conditions: [Disease]
 
 
 
 
 
 
 
 
223
 
224
- Intervention / Treatment
225
- [DRUGs]
226
 
227
- Location
228
- [Location]
229
 
230
- Study Design and Phases
231
- Study Type:
232
- Phase:
233
- Primary Purpose:
234
- Allocation:
235
- Interventional Model:
236
- Masking:"""
237
-
238
- hf_writer = gr.HuggingFaceDatasetSaver(hf_token=token_w_feedback, dataset_name="nttwt1597/criteria-feedback-demo", private=True)
239
-
240
- prompt_box = gr.Textbox(
241
- lines=10,
242
- label=" Research Information",
243
- # placeholder=place_holder,
244
- value=prefilled_value,
245
- )
246
 
247
- output_box = gr.Textbox(
248
- lines=10,
249
- label="Eligible criteria Criteria",
250
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
252
- demo = gr.Interface(
253
- fn=get_prompt,
254
- inputs=prompt_box,
255
- outputs=output_box,
256
- allow_flagging="manual",
257
- flagging_options=["appropriate", "inappropriate", "incorrect",],
258
- flagging_callback=hf_writer,
259
  )
260
 
261
- demo.queue(max_size=20,default_concurrency_limit=5 ).launch(debug=True, share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import time
3
+ import asyncio
 
 
 
 
 
 
 
 
 
4
  from llama_index.core.query_engine import CitationQueryEngine
5
  from llama_index.core import VectorStoreIndex
6
+ from llama_index.core import Settings
7
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
8
+ from llama_index.llms.gemini import Gemini
9
  from llama_index.core.postprocessor import SimilarityPostprocessor
10
 
11
+ HF_TOKEN=os.environ["HUGGINGFACE_TOKEN"]
12
+ API_KEY=os.environ["GOOGLE_API_KEY"]
13
+
14
+ generation_config = {
15
+ "temperature": 0,
16
+ # "top_p": 1,
17
+ # "top_k": 1,
18
+ "max_output_tokens":8192,
19
+ }
20
+
21
+ safety_settings = [
22
+ {
23
+ "category": "HARM_CATEGORY_HARASSMENT",
24
+ "threshold": "BLOCK_NONE"
25
+ },
26
+ {
27
+ "category": "HARM_CATEGORY_HATE_SPEECH",
28
+ "threshold": "BLOCK_NONE"
29
+ },
30
+ {
31
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
32
+ "threshold": "BLOCK_NONE"
33
+ },
34
+ {
35
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
36
+ "threshold": "BLOCK_NONE"
37
+ },
38
  ]
39
 
40
+ llm = Gemini(
41
+ model="models/gemini-1.5-flash-002",
42
+ generation_config=generation_config,
43
+ safety_settings=safety_settings,
 
44
  )
45
 
46
+ # Setup embedder
47
+ embed_model_name = "BAAI/bge-small-en-v1.5"
48
+ embed_model = HuggingFaceEmbedding(model_name=embed_model_name)
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  Settings.llm = llm
51
+ Settings.embed_model = embed_model
52
 
53
+ #to-do: get data
 
 
 
 
 
 
 
54
 
55
+ async def run_function_on_text(top_k,study_obj,study_type,phase,purpose,allocation,intervention_model,Masking,conditions,interventions,location_countries,removed_location_countries):
56
 
57
+ # Set up query engine
58
+ query_engine_get_study = CitationQueryEngine.from_args(
59
+ index_persisted,
60
+ similarity_top_k=top_k,
61
  citation_chunk_size=2048,
 
 
62
  verbose=True,
63
+ node_postprocessors=[SimilarityPostprocessor(similarity_cutoff=0.8)],
64
+ use_async=True
65
+ )
66
+
67
+ #Build prompt
68
+ study_information = f"""
69
+ #Study Objectives/Study Description
70
+ {study_obj}
71
+
72
+ #Intervention
73
+ {interventions}
74
+
75
+ #Location
76
+ - Location_Countries: {location_countries}
77
+ - Removed Location: {removed_location_countries}
78
+
79
+ #Conditions
80
+ Cancer {conditions}
81
+
82
+ #Study Design
83
+ - Study Type: {study_type}
84
+ - Phase: {phase}
85
+ - Primary Purpose: {purpose}
86
+ - Allocation: {allocation}
87
+ - Interventional Model: {intervention_model}
88
+ - Masking: None {Masking}
89
+ """
90
+
91
+ # Query
92
+ query_response = await query_engine_get_study.aquery(f"""
93
+ Based on the provided instructions and clinical trial information, generate the new eligibility criteria by analyzing the related studies and clinical trial information.
94
+ ### Instruction:
95
+ Find suitable papers that have relevant or similar to the clinical trial information(### Clinical Trial Information).
96
+ Prioritize the following topics when finding related studies:
97
+ 1. Study Objectives
98
+ 2. Study Design and Phases
99
+ 3. Conditions
100
+ 4. Intervention/Treatment
101
+
102
+ Criteria generation:
103
+ As a clinical researcher, generate new eligibility criteria for given clinical trial information.
104
+ Analyze the information from related studies for more precise new eligibility criteria generation.
105
+ Ensure the criteria are clear, specific, and reasonable for a clinical research information.
106
+ Do not generate [<number of citation>].
107
+
108
+ Reference Papers generation:
109
+ Please give us NCT IDs and study names for {top_k} used papers.
110
+
111
+ Please follows the pattern of the output(### Pattern of the output).
112
+ --------------------------------------------------
113
+ ### Clinical Trial Information
114
+ {study_information}
115
+ --------------------------------------------------
116
+ ### Pattern of the output
117
+ Inclusion Criteria
118
+ 1.
119
+ 2.
120
+ .
121
+ .
122
+ .
123
+
124
+ Exclusion Criteria
125
+ 1.
126
+ 2.
127
+ .
128
+ .
129
+ .
130
+
131
+ Reference Papers
132
+ 1.NCT ID:
133
+ Study Name:
134
+ Condition:
135
+ Intervention/Treatment:
136
+ 2.NCT ID:
137
+ Study Name:
138
+ Condition:
139
+ Intervention/Treatment:
140
+ .
141
+ .
142
+ .
143
+
144
+
145
+ """
146
+ )
147
 
148
+ # LLM.complete
149
+ complete_response = await llm.acomplete(f"""
150
+ Based on the provided instructions and clinical trial information, generate the new eligibility criteria by analyzing clinical trial information(### Clinical Trial Information).
151
+ ### Instruction:
152
+ Criteria generation:
153
+ As a clinical researcher, generate new eligibility criteria for given clinical trial information.
154
+ Ensure the criteria are clear, specific, and reasonable for a clinical research information.
155
+
156
+ Prioritize the following topics in clinical trial information.:
157
+ 1. Study Objectives
158
+ 2. Study Design and Phases
159
+ 3. Conditions
160
+ 4. Intervention/Treatment
161
+
162
+ Please follows the pattern of the output(### Pattern of the output).
163
+ --------------------------------------------------
164
+ ### Clinical Trial Information
165
+ {study_information}
166
+ --------------------------------------------------
167
+ ### Pattern of the output
168
+ Inclusion Criteria
169
+ 1.
170
+ 2.
171
+ .
172
+ .
173
+ .
174
+
175
+ Exclusion Criteria
176
+ 1.
177
+ 2.
178
+ .
179
+ .
180
+ .
181
+
182
+
183
+ """
184
+
185
+ Combine_response = await llm.acomplete(f"""
186
+ Based on the provided instructions clinical and criteria information, generate the new eligibility criteria by analyzing Criteria 1 (### Criteria 1) and Criteria 2 (### Criteria 2).
187
+ ### Instruction:
188
+ Criteria generation:
189
+ As a clinical researcher, generate eligibility criteria for given information.
190
+ Ensure the criteria are clear, specific, and reasonable for a clinical research information().
191
+
192
+ Prioritize the following topics in clinical trial information.:
193
+ 1. Study Objectives
194
+ 2. Study Design and Phases
195
+ 3. Conditions
196
+ 4. Intervention/Treatment
197
+
198
+ Please follows the pattern of the output(### Pattern of the output).
199
+ --------------------------------------------------
200
+ ### Clinical Trial Information
201
+ {study_information}
202
+ --------------------------------------------------
203
+ ### Pattern of the output
204
+ Inclusion Criteria
205
+ 1.
206
+ 2.
207
+ .
208
+ .
209
+ .
210
+
211
+ Exclusion Criteria
212
+ 1.
213
+ 2.
214
+ .
215
+ .
216
+ .
217
+
218
+
219
+ """
 
 
 
 
 
 
220
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
+ return query_response,complete_response
223
 
224
+ # Place holder
225
  place_holder = f"""Study Objectives
226
  The purpose of this study is to evaluate the safety, tolerance and efficacy of Liposomal Paclitaxel With Nedaplatin as First-line in patients with Advanced or Recurrent Esophageal Carcinoma
227
 
 
240
  Interventional Model: SINGLE_GROUP Masking: NONE
241
  """
242
 
243
+ objective_place_holder = f"""Example: The purpose of this study is to evaluate the safety, tolerance and efficacy of Liposomal Paclitaxel With Nedaplatin as First-line in patients with Advanced or Recurrent Esophageal Carcinoma
244
+ """
245
+
246
+ conditions_place_holder = f"""Example: Esophageal Carcinoma
247
+ """
248
 
249
+ interventions_place_holder = f"""Example:
250
+ - Drug: irinotecan hydrochloride
251
+ - Given IV
252
+ - Other Names:
253
+ - Campto
254
+ - Camptosar
255
+ - CPT-11
256
+ - irinotecan
257
+ - U-101440E
258
 
259
+ - Drug: Amoxicillin hydrate
260
+ - Amoxicillin hydrate (potency)
261
 
262
+ - Procedure: Stem cell transplant
263
+ - See Detailed Description section for details of treatment interventions.
264
 
265
+ - Biological: Pneumococcal Vaccine
266
+ - Subcutaneously on Day 0
267
+ - Other Names:
268
+ - Prevnar
 
 
 
 
 
 
 
 
 
 
 
 
269
 
270
+ - Drug: Doxorubicin, Cotrimoxazole, Carboplatin, Ifosfamide
271
+
272
+ - Drug: Irinotecan
273
+ - Irinotecan will be administered at a dose of 180mg/m2 IV over 90 minutes on day 21 every 42 days.
274
+ - Other Names:
275
+ - CAMPTOSAR™
276
+
277
+ - Drug: Placeblo
278
+ - Placebo tablet
279
+ """
280
+
281
+ prefilled_value = f"""Study Objectives The purpose of this study is to find out if the combination of docetaxel and capecitabine can shrink the size of breast tumors and preserve the breast. Conditions: Breast Cancer Intervention / Treatment: DRUG: Docetaxel, DRUG: Capecitabine Location: United States Study Design and Phases Study Type: INTERVENTIONAL Phase: PHASE2 Primary Purpose: TREATMENT Allocation: RANDOMIZED Interventional Model: PARALLEL Masking: NONE"""
282
+
283
+ custom_css = """
284
+ .gradio-container {
285
+ font-family: 'Roboto', sans-serif;
286
+ }
287
+ .main-header {
288
+ text-align: center;
289
+ color: #4a4a4a;
290
+ margin-bottom: 2rem;
291
+ }
292
+ .tab-header {
293
+ font-size: 1.2rem;
294
+ font-weight: bold;
295
+ margin-bottom: 1rem;
296
+ }
297
+ .custom-chatbot {
298
+ border-radius: 10px;
299
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
300
+ }
301
+ .custom-button {
302
+ background-color: #3498db;
303
+ color: white;
304
+ border: none;
305
+ padding: 10px 20px;
306
+ border-radius: 5px;
307
+ cursor: pointer;
308
+ transition: background-color 0.3s ease;
309
+ }
310
+ .custom-button:hover {
311
+ background-color: #2980b9;
312
+ }
313
+ """
314
 
315
+ # Define Gradio theme
316
+ theme = gr.themes.Default(
317
+ primary_hue="zinc",
318
+ secondary_hue="red",
319
+ neutral_hue="neutral",
320
+ font=[gr.themes.GoogleFont('Roboto'), "sans-serif"]
 
321
  )
322
 
323
+ with gr.Blocks() as demo:
324
+
325
+ with gr.Row():
326
+ gr.Markdown("# Reference paper"),
327
+ with gr.Row():
328
+ top_k_box = gr.Slider(
329
+ label="Amount of reference paper",
330
+ value=5,
331
+ minimum=0,
332
+ maximum=30,
333
+ step=1,
334
+ )
335
+ # Study description
336
+ with gr.Row():
337
+ gr.Markdown("# Research Information"),
338
+ with gr.Row():
339
+ study_obj_box = gr.Textbox(
340
+ label="Study Objective / Study Description", # Study description
341
+ placeholder=objective_place_holder,
342
+ lines=10)
343
+ # Study Design
344
+ with gr.Row():
345
+ gr.Markdown("# Study Design"),
346
+ with gr.Column():
347
+ study_type_box = gr.Radio(
348
+ ["Expanded Access", "Interventional", "Observational"],
349
+ label="Study Type",
350
+ )
351
+ phase_box= gr.Radio(
352
+ ["Not Applicable", "Early Phase 1", "Phase 1", "Phase 2", "Phase 3", "Phase 4"],
353
+ label="Phase"
354
+ )
355
+ purpose_box = gr.Radio(
356
+ ["Treatment", "Prevention", "Diagnostic", "Educational/Counseling/Training", "Supportive Care", "Screening", "Health Services Research", "Basic Science", "Device Feasibility", "Other"],
357
+ label="Primary Purpose"
358
+ )
359
+ allocation_box = gr.Radio(
360
+ ["Randomized", "Non-Randomized", "N/A"],
361
+ label="Allocation"
362
+ )
363
+ intervention_model_box = gr.Radio(
364
+ ["Parallel", "Single-Group", "Crossover", "Factorial", "Sequential"],
365
+ label="Interventional Model"
366
+ )
367
+ masking_box = gr.Radio(
368
+ ["None (Open Label)", "Single", "Double", "Triple", "Quadruple"],
369
+ label="Masking"
370
+ )
371
+ # Conditions
372
+ with gr.Row():
373
+ gr.Markdown("# Conditions"),
374
+ with gr.Row():
375
+ conditions_box = gr.Textbox(
376
+ label="Conditions / Disease",
377
+ info="Primary Disease or Condition of Cancer Being Studied in the Trial, or the Focus of the Study",
378
+ placeholder=conditions_place_holder,
379
+ )
380
+ #Interventions
381
+ with gr.Row():
382
+ gr.Markdown("# Interventions / Drugs"),
383
+ with gr.Row():
384
+ intervention_box = gr.Textbox(
385
+ label="Intervention type",
386
+ placeholder=interventions_place_holder,
387
+ )
388
+ #Location
389
+ with gr.Row():
390
+ gr.Markdown("# Location"),
391
+ with gr.Column():
392
+ location_box = gr.Textbox(
393
+ label="Location (Countries)",
394
+ )
395
+ removed_location_box = gr.Textbox(
396
+ label="Removed Location (Countries)",
397
+ )
398
+
399
+ # Submit & Clear
400
+ with gr.Row():
401
+ submit_button = gr.Button("Submit")
402
+ clear_button = gr.Button("Clear")
403
+
404
+ # Output
405
+ with gr.Row():
406
+ gr.Markdown("# Eligibility Criteria Generation"),
407
+ with gr.Row():
408
+ with gr.Column():
409
+ base_box = gr.Textbox(
410
+ label="Response 1",
411
+ lines=5,
412
+ interactive=False)
413
+ with gr.Column():
414
+ rag_box = gr.Textbox(
415
+ label="Response 2",
416
+ lines=5,
417
+ interactive=False)
418
+
419
+ submit_button.click(
420
+ run_function_on_text,
421
+ inputs=[top_k_box,study_obj_box,study_type_box,phase_box,purpose_box,allocation_box,intervention_model_box,masking_box,conditions_box,intervention_box,location_box,removed_location_box],
422
+ outputs=[base_box, rag_box]
423
+ )
424
+
425
+ inputs_information = [top_k_box, study_obj_box, study_type_box, phase_box, purpose_box, allocation_box, intervention_model_box, masking_box, conditions_box, intervention_box, location_box, removed_location_box]
426
+
427
+ clear_button.click(lambda : [None] * len(inputs_information), outputs=inputs_information)
428
+
429
+
430
+ with gr.Row():
431
+ selected_response = gr.Radio(
432
+ choices=[
433
+ "Response 1 is better",
434
+ "Response 2 is better",
435
+ "Both responses are equally good",
436
+ "Neither response is satisfactory"
437
+ ],
438
+ label="Select the better response"
439
+ )
440
+ with gr.Row():
441
+ flag_button = gr.Button("Flag Selected Response")
442
+
443
+ #Flagging
444
+ callback = gr.CSVLogger()
445
+ callback.setup([selected_response, study_obj_box, study_type_box, phase_box, purpose_box, allocation_box, intervention_model_box, masking_box, conditions_box, intervention_box, location_box, removed_location_box, top_k_box, base_box, rag_box], "flagged_data_points")
446
+
447
+ flag_button.click(lambda *args: callback.flag(list(args)), [selected_response, study_obj_box, study_type_box, phase_box, purpose_box, allocation_box, intervention_model_box, masking_box, conditions_box, intervention_box, location_box, removed_location_box, top_k_box, base_box, rag_box], None, preprocess=False)
448
+
449
+ with gr.Row():
450
+ clear_all_button = gr.Button("Clear All")
451
+
452
+ output_information = inputs_information + [base_box, rag_box, selected_response]
453
+ clear_all_button.click(lambda : [None] * len(output_information), outputs=output_information)
454
+
455
+ if __name__ == "__main__":
456
+ demo.launch(debug=True)