Update app.py
Browse files
app.py
CHANGED
|
@@ -9,8 +9,11 @@ model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
| 9 |
model.eval()
|
| 10 |
|
| 11 |
# Function to compute relevance score (in logits) and dynamically adjust threshold
|
| 12 |
-
def get_relevance_score_and_excerpt(query,
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
return "Please provide both a query and at least one document paragraph.", ""
|
| 15 |
|
| 16 |
ranked_paragraphs = []
|
|
@@ -74,7 +77,7 @@ def get_relevance_score_and_excerpt(query, *paragraphs, threshold_weight):
|
|
| 74 |
relevance_scores = [round(p["logit"], 4) for p in ranked_paragraphs]
|
| 75 |
highlighted_texts = [p["highlighted_text"] for p in ranked_paragraphs]
|
| 76 |
|
| 77 |
-
return "\n".join([f"Relevance Score: {score}" for score in relevance_scores]), "\n\n".join(highlighted_texts)
|
| 78 |
|
| 79 |
# Define Gradio interface with a slider for threshold adjustment and ability to add multiple paragraphs
|
| 80 |
interface = gr.Interface(
|
|
@@ -97,4 +100,4 @@ interface = gr.Interface(
|
|
| 97 |
)
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
-
interface.launch()
|
|
|
|
| 9 |
model.eval()
|
| 10 |
|
| 11 |
# Function to compute relevance score (in logits) and dynamically adjust threshold
|
| 12 |
+
def get_relevance_score_and_excerpt(query, paragraph1, paragraph2, paragraph3, threshold_weight):
|
| 13 |
+
# Handle empty input for paragraphs
|
| 14 |
+
paragraphs = [p for p in [paragraph1, paragraph2, paragraph3] if p.strip()]
|
| 15 |
+
|
| 16 |
+
if not query.strip() or not paragraphs:
|
| 17 |
return "Please provide both a query and at least one document paragraph.", ""
|
| 18 |
|
| 19 |
ranked_paragraphs = []
|
|
|
|
| 77 |
relevance_scores = [round(p["logit"], 4) for p in ranked_paragraphs]
|
| 78 |
highlighted_texts = [p["highlighted_text"] for p in ranked_paragraphs]
|
| 79 |
|
| 80 |
+
return "\n".join([f"Relevance Score (Logits): {score}" for score in relevance_scores]), "\n\n".join(highlighted_texts)
|
| 81 |
|
| 82 |
# Define Gradio interface with a slider for threshold adjustment and ability to add multiple paragraphs
|
| 83 |
interface = gr.Interface(
|
|
|
|
| 100 |
)
|
| 101 |
|
| 102 |
if __name__ == "__main__":
|
| 103 |
+
interface.launch()
|