Spaces:
Runtime error
Runtime error
| 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() | |