Spaces:
Runtime error
Runtime error
Create app.py
#1
by
Elevi7
- opened
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
from sentence_transformers import SentenceTransformer
|
4 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
# Load dataset
|
8 |
+
dataset = load_dataset("Levimichael4/BioHackBuddy-Healthadvice", split="train")
|
9 |
+
df = pd.DataFrame(dataset)
|
10 |
+
|
11 |
+
# Load embedding model
|
12 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
13 |
+
issue_embeddings = model.encode(df["Issue"].tolist(), convert_to_tensor=True)
|
14 |
+
|
15 |
+
# Recommend top 3 similar entries
|
16 |
+
def recommend(user_input):
|
17 |
+
input_emb = model.encode([user_input], convert_to_tensor=True)
|
18 |
+
sims = cosine_similarity(input_emb, issue_embeddings)[0]
|
19 |
+
top_indices = sims.argsort()[-3:][::-1]
|
20 |
+
results = df.iloc[top_indices][["Issue", "Suggestion 1", "Suggestion 2", "Suggestion 3"]]
|
21 |
+
return results.to_markdown(index=False)
|
22 |
+
|
23 |
+
# Gradio UI
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=recommend,
|
26 |
+
inputs=gr.Textbox(label="Describe your issue or health goal"),
|
27 |
+
outputs=gr.Markdown(label="Top 3 Suggestions"),
|
28 |
+
examples=[
|
29 |
+
["I feel tired every morning"],
|
30 |
+
["I want to improve focus"],
|
31 |
+
["I can't sleep well at night"]
|
32 |
+
],
|
33 |
+
title="🧠 BioHackBuddy - Personalized Wellness Advice",
|
34 |
+
description="Get science-backed lifestyle suggestions based on your personal wellness challenge or goal."
|
35 |
+
)
|
36 |
+
|
37 |
+
demo.launch()
|
38 |
+
|