File size: 1,328 Bytes
f06595c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
from datasets import load_dataset
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import pandas as pd

# Load dataset
dataset = load_dataset("Levimichael4/BioHackBuddy-Healthadvice", split="train")
df = pd.DataFrame(dataset)

# Load embedding model
model = SentenceTransformer("all-MiniLM-L6-v2")
issue_embeddings = model.encode(df["Issue"].tolist(), convert_to_tensor=True)

# Recommend top 3 similar entries
def recommend(user_input):
    input_emb = model.encode([user_input], convert_to_tensor=True)
    sims = cosine_similarity(input_emb, issue_embeddings)[0]
    top_indices = sims.argsort()[-3:][::-1]
    results = df.iloc[top_indices][["Issue", "Suggestion 1", "Suggestion 2", "Suggestion 3"]]
    return results.to_markdown(index=False)

# Gradio UI
demo = gr.Interface(
    fn=recommend,
    inputs=gr.Textbox(label="Describe your issue or health goal"),
    outputs=gr.Markdown(label="Top 3 Suggestions"),
    examples=[
        ["I feel tired every morning"],
        ["I want to improve focus"],
        ["I can't sleep well at night"]
    ],
    title="🧠 BioHackBuddy - Personalized Wellness Advice",
    description="Get science-backed lifestyle suggestions based on your personal wellness challenge or goal."
)

demo.launch()