skill-ranking / app.py
vaibhav-ceew's picture
Update app.py
657a6ed verified
import gradio as gr
from sentence_transformers import CrossEncoder
def rank_tasks(query, tasks_string):
model = CrossEncoder("vaibhav-ceew/onet-msmacroL6")
tasks = [task.strip() for task in tasks_string.split(',')]
scores = model.predict([(query, task) for task in tasks])
scored_tasks = list(zip(tasks, scores))
sorted_tasks = sorted(scored_tasks, key=lambda x: x[1], reverse=True)
output_string = ""
for task, score in sorted_tasks:
output_string += f"{task} ,{score:.4f}\n"
return output_string
# Sample Query and Tasks
sample_query = "Which planet is known as the Red Planet?"
sample_tasks = "Venus is often called Earth's twin because of its similar size and proximity.,Mars, known for its reddish appearance, is often referred to as the Red Planet.,Jupiter, the largest planet in our solar system, has a prominent red spot.,Saturn, famous for its rings, is sometimes mistaken for the Red Planet."
demo = gr.Interface(
fn=rank_tasks,
inputs=[
gr.Textbox(label="Enter your query"),
gr.Textbox(label="Enter tasks separated by comma")
],
outputs=gr.Textbox(label="Ranked Tasks"),
title="Task Relevance Ranking",
description="Enter a query and a comma-separated list of tasks to see their relevance ranking.",
examples=[[sample_query, sample_tasks]]
)
demo.launch()