ds-EkaCare commited on
Commit
df6f47b
·
verified ·
1 Parent(s): 0f537fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -36
app.py CHANGED
@@ -79,7 +79,9 @@ class ParrotletRetriever:
79
  return docs
80
 
81
 
82
-
 
 
83
  MODEL_NAME = "ekacare/parrotlet-e"
84
  retriever = ParrotletRetriever(MODEL_NAME)
85
 
@@ -95,62 +97,102 @@ def retrieve_documents(query: str, top_k: int = 5):
95
  return pd.DataFrame(), "No results found."
96
 
97
  df = pd.DataFrame(results)
98
- status = f"Retrieved top {len(results)} documents."
99
  return df, status
100
 
101
  except Exception as e:
102
- return pd.DataFrame(), f"Error: {str(e)}"
103
 
104
 
105
  # =========================
106
- # Gradio Interface
107
  # =========================
108
  SAMPLE_QUERIES = [
109
- "dm t2",
 
 
 
110
  "छाती में दर्द",
111
  "talenovu",
112
  "వాంతులు"
 
 
 
 
 
 
 
113
  ]
114
 
115
  with gr.Blocks(title="Parrotlet-e Retrieval", theme=gr.themes.Soft()) as demo:
116
 
117
- with gr.Row():
118
- with gr.Column(scale=1):
119
- query_input = gr.Textbox(
120
- label="Enter a medical term",
121
- placeholder="Type your query here...",
122
- lines=1,
123
- )
124
-
125
- examples = gr.Examples(
126
- examples=SAMPLE_QUERIES,
127
- inputs=query_input,
128
- label="Example Queries"
129
- )
130
-
131
- top_k_input = gr.Number(
132
- label="K",
133
- value=5,
134
- precision=0,
135
- interactive=True
136
- )
137
-
138
- search_btn = gr.Button("retrieve", variant="primary")
139
-
140
- with gr.Column(scale=2):
141
- results_output = gr.Dataframe(
142
- headers=["Rank", "Score", "Document", "ID"],
143
- datatype=["number", "str", "str", "str"],
144
- interactive=False,
145
- wrap=True
146
- )
147
- status_box = gr.Textbox(label="Status", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  search_btn.click(
150
  fn=retrieve_documents,
151
  inputs=[query_input, top_k_input],
152
  outputs=[results_output, status_box],
153
  )
154
 
 
155
  if __name__ == "__main__":
156
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
79
  return docs
80
 
81
 
82
+ # =========================
83
+ # Instantiate Retriever
84
+ # =========================
85
  MODEL_NAME = "ekacare/parrotlet-e"
86
  retriever = ParrotletRetriever(MODEL_NAME)
87
 
 
97
  return pd.DataFrame(), "No results found."
98
 
99
  df = pd.DataFrame(results)
100
+ status = f"Retrieved top {len(results)} documents."
101
  return df, status
102
 
103
  except Exception as e:
104
+ return pd.DataFrame(), f"⚠️ Error: {str(e)}"
105
 
106
 
107
  # =========================
108
+ # Gradio Interface (VERTICAL)
109
  # =========================
110
  SAMPLE_QUERIES = [
111
+ "takhne me dard",
112
+ "ghotyalu dard",
113
+ "ghera aana",
114
+ "vayiru vali",
115
  "छाती में दर्द",
116
  "talenovu",
117
  "వాంతులు"
118
+ "ಕಾಮಲೆ", # jaundice
119
+ "பேசுவது சிரமம்", # Dysphasia
120
+ "Peshab Kartaana Jalan", # Scalding pain on urination
121
+ "Kurunnal",
122
+ "sunn hua",
123
+ "moochithinaral",
124
+ "মাথাব্যথা"
125
  ]
126
 
127
  with gr.Blocks(title="Parrotlet-e Retrieval", theme=gr.themes.Soft()) as demo:
128
 
129
+ # ---- Header ----
130
+ gr.Markdown(
131
+ """
132
+ <h1 style='text-align:center; color:#2b4162;'>🦜 Parrotlet-e Retrieval</h1>
133
+ <p style='text-align:center; font-size:16px; color:#555;'>
134
+ Multilingual Medical Embedding Search powered by <b>EkaCare's Parrotlet-e</b> model
135
+ </p>
136
+ <hr>
137
+ """,
138
+ )
139
+
140
+ # ---- Model Description ----
141
+ gr.Markdown(
142
+ """
143
+ ### 🧠 Model Description
144
+ **Parrotlet-e: Indic Medical Entity Embedding Model**
145
+ A multilingual embedding model designed to represent Indian medical terminology across multiple scripts and languages.
146
+
147
+ - 🔗 **Model on Hugging Face:** [ekacare/parrotlet-e](https://huggingface.co/ekacare/parrotlet-e)
148
+ - 📊 **Benchmarked on:** [Eka-IndicMTEB](https://huggingface.co/datasets/ekacare/Eka-IndicMTEB)
149
+ - 📰 Read more on our [blog](https://info.eka.care/services/introducing-parrotlet-e-and-eka-indicmteb-bridging-indias-multilingual-healthcare-gap)
150
+
151
+ ---
152
+ """,
153
+ )
154
+
155
+ # ---- Input Section ----
156
+ with gr.Group():
157
+ query_input = gr.Textbox(
158
+ label="Enter a medical term (not sentences in any language)",
159
+ placeholder="Type your query here...",
160
+ lines=1,
161
+ )
162
+
163
+ examples = gr.Examples(
164
+ examples=SAMPLE_QUERIES,
165
+ inputs=query_input,
166
+ label="💡 Example Queries"
167
+ )
168
+
169
+ top_k_input = gr.Number(
170
+ label="Number of results (K)",
171
+ value=5,
172
+ precision=0,
173
+ interactive=True
174
+ )
175
 
176
+ search_btn = gr.Button("🔍 retrieve", variant="primary")
177
+
178
+ # ---- Output Section ----
179
+ with gr.Group():
180
+ results_output = gr.Dataframe(
181
+ headers=["Rank", "Score", "Term", "ID"],
182
+ datatype=["number", "str", "str", "str"],
183
+ interactive=False,
184
+ wrap=True,
185
+ label="📄 Search Results"
186
+ )
187
+ status_box = gr.Textbox(label="Status", interactive=False)
188
+
189
+ # ---- Function Binding ----
190
  search_btn.click(
191
  fn=retrieve_documents,
192
  inputs=[query_input, top_k_input],
193
  outputs=[results_output, status_box],
194
  )
195
 
196
+
197
  if __name__ == "__main__":
198
  demo.launch(server_name="0.0.0.0", server_port=7860)