Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,13 +4,13 @@ from sentence_transformers import SentenceTransformer, util
|
|
| 4 |
|
| 5 |
# Load dataset
|
| 6 |
df = pd.read_csv("quotes.csv")
|
| 7 |
-
quotes = df["quote"].tolist()
|
| 8 |
|
| 9 |
# Load embedding model
|
| 10 |
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 11 |
quote_embeddings = model.encode(quotes, convert_to_tensor=True)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
def get_top3(user_input):
|
| 15 |
if not user_input.strip():
|
| 16 |
return "Please enter a search phrase."
|
|
@@ -25,13 +25,13 @@ def get_top3(user_input):
|
|
| 25 |
|
| 26 |
return "\n".join(output_quotes)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
demo = gr.Interface(
|
| 30 |
fn=get_top3,
|
| 31 |
inputs=gr.Textbox(lines=2, placeholder="Type something..."),
|
| 32 |
outputs="text",
|
| 33 |
-
title="Quote Finder
|
| 34 |
-
description="
|
| 35 |
examples=[
|
| 36 |
["happiness"],
|
| 37 |
["overcoming failure"],
|
|
|
|
| 4 |
|
| 5 |
# Load dataset
|
| 6 |
df = pd.read_csv("quotes.csv")
|
| 7 |
+
quotes = df["quote"].dropna().tolist()
|
| 8 |
|
| 9 |
# Load embedding model
|
| 10 |
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 11 |
quote_embeddings = model.encode(quotes, convert_to_tensor=True)
|
| 12 |
|
| 13 |
+
# Recommendation function
|
| 14 |
def get_top3(user_input):
|
| 15 |
if not user_input.strip():
|
| 16 |
return "Please enter a search phrase."
|
|
|
|
| 25 |
|
| 26 |
return "\n".join(output_quotes)
|
| 27 |
|
| 28 |
+
# Gradio app
|
| 29 |
demo = gr.Interface(
|
| 30 |
fn=get_top3,
|
| 31 |
inputs=gr.Textbox(lines=2, placeholder="Type something..."),
|
| 32 |
outputs="text",
|
| 33 |
+
title="Quote Finder",
|
| 34 |
+
description="Find 3 quotes similar to your input using AI embeddings.",
|
| 35 |
examples=[
|
| 36 |
["happiness"],
|
| 37 |
["overcoming failure"],
|