| import gradio as gr |
| from sentence_transformers import SentenceTransformer, util |
|
|
| |
| model = SentenceTransformer("sangambhamare/MarathiSentenceSimilarity") |
|
|
| def compute_similarity(sent1, sent2): |
| emb1 = model.encode(sent1, convert_to_tensor=True) |
| emb2 = model.encode(sent2, convert_to_tensor=True) |
| score = util.pytorch_cos_sim(emb1, emb2).item() |
| return f"{score * 100:.2f}%" |
|
|
| |
| with open("interactive_report.html", "r", encoding="utf-8") as f: |
| report_html = f.read() |
|
|
| |
| with gr.Blocks(title="Evaluating & Enhancing Marathi Sentence Similarity") as demo: |
|
|
| |
| gr.HTML( |
| """ |
| <div style="text-align:center; margin-bottom:2rem;"> |
| <h1>Evaluating & Enhancing Marathi Sentence Similarity</h1> |
| <p style="text-align:center; font-size:1.1em; margin-top:0;"> |
| <em>An interactive exploration of adapting AI for a low-resource language.</em> |
| </p> |
| </div> |
| """ |
| ) |
|
|
| |
| gr.HTML( |
| """ |
| <div style="text-align:center; margin-bottom:1.5rem;"> |
| <h2>Marathi Sentence Similarity Demo</h2> |
| </div> |
| """ |
| ) |
|
|
| |
| with gr.Row(): |
| sent1 = gr.Textbox( |
| label="वाक्य १ (Sentence 1)", |
| lines=2, |
| placeholder="तो शाळेत जातो.", |
| elem_id="input1" |
| ) |
| sent2 = gr.Textbox( |
| label="वाक्य २ (Sentence 2)", |
| lines=2, |
| placeholder="तो विद्यालयात जातो.", |
| elem_id="input2" |
| ) |
| btn = gr.Button("Compute Similarity") |
| result = gr.Textbox(label="Similarity Score", interactive=False) |
| btn.click(fn=compute_similarity, inputs=[sent1, sent2], outputs=result) |
|
|
| |
| gr.HTML(f"""<div style="width:100%; overflow-x:auto;">{report_html}</div>""") |
|
|
| if __name__ == "__main__": |
| demo.launch() |