FaishalbhiteX commited on
Commit
77a7dcf
·
verified ·
1 Parent(s): ee255b6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import faiss
3
+ import numpy as np
4
+ import pandas as pd
5
+ from sentence_transformers import SentenceTransformer
6
+
7
+ # Load model embedding
8
+ embed_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
9
+
10
+ # Load FAISS index
11
+ index = faiss.read_index("laptop_index.faiss")
12
+ embeddings = np.load("laptop_embeddings.npy")
13
+
14
+ # Load dataset
15
+ df = pd.read_csv("laptop_data.csv")
16
+
17
+ # Function untuk rekomendasi
18
+ def recommend_laptops(query, top_k=5):
19
+ query_embedding = embed_model.encode([query])
20
+ D, I = index.search(query_embedding, top_k)
21
+ results = df.iloc[I[0]][["Company", "TypeName", "CPU_Type", "GPU_Company", "Price (Euro)"]]
22
+ return results.to_dict(orient="records")
23
+
24
+ # Gradio UI
25
+ demo = gr.Interface(
26
+ fn=recommend_laptops,
27
+ inputs="text",
28
+ outputs="json",
29
+ title="Laptop Recommender",
30
+ description="Masukkan spesifikasi yang Anda inginkan untuk rekomendasi laptop."
31
+ )
32
+
33
+ demo.launch()