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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -58
app.py CHANGED
@@ -97,15 +97,15 @@ def retrieve_documents(query: str, top_k: int = 5):
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",
@@ -114,85 +114,93 @@ SAMPLE_QUERIES = [
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)
 
97
  return pd.DataFrame(), "No results found."
98
 
99
  df = pd.DataFrame(results)
100
+ status = f"Retrieved {len(results)} results"
101
  return df, status
102
 
103
  except Exception as e:
104
+ return pd.DataFrame(), f"Error: {str(e)}"
105
 
106
 
107
  # =========================
108
+ # Gradio Interface (SIMPLE & ELEGANT)
109
  # =========================
110
  SAMPLE_QUERIES = [
111
  "takhne me dard",
 
114
  "vayiru vali",
115
  "छाती में दर्द",
116
  "talenovu",
117
+ "వాంతులు",
118
+ "ಕಾಮಲೆ",
119
+ "பேசுவது சிரமம்",
120
+ "Peshab Kartaana Jalan",
121
  "Kurunnal",
122
  "sunn hua",
123
  "moochithinaral",
124
  "মাথাব্যথা"
125
  ]
126
 
127
+ # Custom CSS for elegant styling
128
+ custom_css = """
129
+ .gradio-container {
130
+ max-width: 900px !important;
131
+ margin: auto !important;
132
+ }
133
+ footer {
134
+ display: none !important;
135
+ }
136
+ """
137
 
138
+ with gr.Blocks(title="Parrotlet-e", theme=gr.themes.Soft(), css=custom_css) as demo:
 
 
 
 
 
 
 
 
 
139
 
 
140
  gr.Markdown(
141
  """
142
+ # Parrotlet-e
143
+ Multilingual medical term search across Indian languages
 
 
 
 
 
 
 
144
  """,
145
+ elem_classes="header"
146
  )
147
 
148
+ query_input = gr.Textbox(
149
+ label="Search medical term",
150
+ placeholder="Enter a medical term in any language...",
151
+ lines=1,
152
+ scale=4
153
+ )
 
 
 
 
 
 
 
154
 
155
+ with gr.Row():
156
+ top_k_input = gr.Slider(
157
+ label="Results",
158
+ minimum=1,
159
+ maximum=20,
160
  value=5,
161
+ step=1,
162
+ scale=1
163
  )
164
+ search_btn = gr.Button("Search", variant="primary", scale=1)
165
+
166
+ gr.Examples(
167
+ examples=SAMPLE_QUERIES,
168
+ inputs=query_input,
169
+ label="Try these examples"
170
+ )
171
 
172
+ results_output = gr.Dataframe(
173
+ headers=["Rank", "Score", "Term", "ID"],
174
+ datatype=["number", "str", "str", "str"],
175
+ interactive=False,
176
+ wrap=True,
177
+ label="Results"
178
+ )
179
+
180
+ # status_box = gr.Textbox(label="", interactive=False, show_label=False)
181
 
182
+ gr.Markdown(
183
+ """
184
+ ---
185
+ Model: [ekacare/parrotlet-e](https://huggingface.co/ekacare/parrotlet-e) |
186
+ Benchmark: [Eka-IndicMTEB](https://huggingface.co/datasets/ekacare/Eka-IndicMTEB) |
187
+ [Learn more](https://info.eka.care/services/introducing-parrotlet-e-and-eka-indicmteb-bridging-indias-multilingual-healthcare-gap)
188
+ """,
189
+ elem_classes="footer-links"
190
+ )
 
191
 
 
192
  search_btn.click(
193
  fn=retrieve_documents,
194
  inputs=[query_input, top_k_input],
195
  outputs=[results_output, status_box],
196
  )
197
 
198
+ query_input.submit(
199
+ fn=retrieve_documents,
200
+ inputs=[query_input, top_k_input],
201
+ outputs=[results_output],
202
+ )
203
+
204
 
205
  if __name__ == "__main__":
206
+ demo.launch(server_name="0.0.0.0", server_port=7860)