Elevi7 commited on
Commit
6902bea
·
verified ·
1 Parent(s): d3c7125

Create app.

Browse files
Files changed (1) hide show
  1. app. +39 -0
app. ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from sentence_transformers import SentenceTransformer, util
3
+ import torch
4
+
5
+ # Sample quote dataset
6
+ quotes = [
7
+ "You are stronger than you think.",
8
+ "It's okay to take a break.",
9
+ "Progress, not perfection.",
10
+ "Breathe. You’re doing better than you think.",
11
+ "Small steps still move you forward.",
12
+ "This feeling is temporary.",
13
+ "One day at a time.",
14
+ "You got this.",
15
+ "Your value is not measured by productivity.",
16
+ "Kindness starts with yourself."
17
+ ]
18
+
19
+ # Load the embedding model
20
+ model = SentenceTransformer('all-MiniLM-L6-v2')
21
+ quote_embeddings = model.encode(quotes, convert_to_tensor=True)
22
+
23
+ # Recommendation function
24
+ def recommend_quote(user_input):
25
+ user_embedding = model.encode(user_input, convert_to_tensor=True)
26
+ similarities = util.pytorch_cos_sim(user_embedding, quote_embeddings)
27
+ top_results = torch.topk(similarities, k=3)
28
+ recommended = [quotes[i] for i in top_results.indices[0]]
29
+ return "\n\n".join(recommended)
30
+
31
+ # Gradio UI
32
+ interface = gr.Interface(
33
+ fn=recommend_quote,
34
+ inputs=gr.Textbox(placeholder="Type how you feel..."),
35
+ outputs="text",
36
+ title="MoodMatch",
37
+ description="Type how you feel. Get 3 uplifting quotes powered by AI.",
38
+ )
39
+ interface.launch()