Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,10 +5,11 @@ import faiss
|
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
|
| 8 |
-
# --- Load data ---
|
| 9 |
df = pd.read_csv("tariff_codes.csv", encoding="latin1", low_memory=False)
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
# --- Create embeddings ---
|
| 14 |
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
@@ -30,7 +31,11 @@ def generate_answer(user_query):
|
|
| 30 |
_, indices = index.search(query_embedding, k=5)
|
| 31 |
|
| 32 |
context = "\n".join([f"{codes[i]}: {descriptions[i]}" for i in indices[0]])
|
| 33 |
-
prompt = f"""Here are some tariff code descriptions:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
response = client.text_generation(
|
| 36 |
prompt,
|
|
@@ -40,7 +45,7 @@ def generate_answer(user_query):
|
|
| 40 |
)
|
| 41 |
return response.strip()
|
| 42 |
|
| 43 |
-
# --- Gradio
|
| 44 |
gr.ChatInterface(
|
| 45 |
fn=generate_answer,
|
| 46 |
title="Tariff Code RAG Bot (FAISS + Inference API)"
|
|
|
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
from huggingface_hub import InferenceClient
|
| 7 |
|
| 8 |
+
# --- Load and clean data ---
|
| 9 |
df = pd.read_csv("tariff_codes.csv", encoding="latin1", low_memory=False)
|
| 10 |
+
df.columns = df.columns.str.strip()
|
| 11 |
+
descriptions = df["brief_description"].astype(str).tolist()
|
| 12 |
+
codes = df["hts8"].astype(str).tolist()
|
| 13 |
|
| 14 |
# --- Create embeddings ---
|
| 15 |
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
|
|
| 31 |
_, indices = index.search(query_embedding, k=5)
|
| 32 |
|
| 33 |
context = "\n".join([f"{codes[i]}: {descriptions[i]}" for i in indices[0]])
|
| 34 |
+
prompt = f"""Here are some tariff code descriptions:
|
| 35 |
+
{context}
|
| 36 |
+
|
| 37 |
+
Question: {user_query}
|
| 38 |
+
Answer:"""
|
| 39 |
|
| 40 |
response = client.text_generation(
|
| 41 |
prompt,
|
|
|
|
| 45 |
)
|
| 46 |
return response.strip()
|
| 47 |
|
| 48 |
+
# --- Gradio Chat Interface ---
|
| 49 |
gr.ChatInterface(
|
| 50 |
fn=generate_answer,
|
| 51 |
title="Tariff Code RAG Bot (FAISS + Inference API)"
|