Upload app.py
Browse files
app.py
CHANGED
|
@@ -5,21 +5,35 @@ from huggingface_hub import InferenceClient
|
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
print("1.
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
df.
|
| 13 |
-
|
| 14 |
-
df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
print("2. Loading Embedding Model & Vectorizing Data...")
|
| 17 |
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
|
|
|
|
| 18 |
sample_resolutions = df['historical_resolution'].head(100).tolist()
|
| 19 |
resolution_embeddings = model.encode(sample_resolutions)
|
| 20 |
|
| 21 |
print("3. Connecting to LLM...")
|
| 22 |
-
# This pulls the HF_TOKEN securely from the Spaces Settings > Secrets
|
| 23 |
hf_token = os.environ.get("HF_TOKEN")
|
| 24 |
client = InferenceClient(
|
| 25 |
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
|
@@ -59,7 +73,8 @@ with gr.Blocks() as demo:
|
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column():
|
| 62 |
-
|
|
|
|
| 63 |
submit_btn = gr.Button("Resolve Ticket")
|
| 64 |
|
| 65 |
with gr.Column():
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
print("1. Ingesting Data (with Fallback Protection)...")
|
| 9 |
+
try:
|
| 10 |
+
# Attempting to load a highly stable public dataset
|
| 11 |
+
raw_data = load_dataset("Kaludi/Customer-Support-Responses")
|
| 12 |
+
df = pd.DataFrame(raw_data['train'])
|
| 13 |
+
# Standardize the columns for our pipeline
|
| 14 |
+
df = df[['query', 'response']]
|
| 15 |
+
df.columns = ['customer_query', 'historical_resolution']
|
| 16 |
+
print("Cloud dataset loaded successfully.")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Cloud dataset unavailable ({e}). Initializing backup demo dataset...")
|
| 19 |
+
# Defensive programming: Fallback data ensures your portfolio never crashes for a recruiter
|
| 20 |
+
backup_data = [
|
| 21 |
+
{"customer_query": "How do I reset my password?", "historical_resolution": "To reset your password, navigate to the login page and click 'Forgot Password'. You will receive an email with a secure reset link valid for 24 hours."},
|
| 22 |
+
{"customer_query": "Where can I find my monthly invoice?", "historical_resolution": "All invoices are securely located in your account dashboard under the 'Billing & Payments' tab. You can download them directly as PDFs."},
|
| 23 |
+
{"customer_query": "How do I cancel my current subscription?", "historical_resolution": "To cancel your subscription, go to Settings > Subscription and click 'Cancel Plan'. Your access will remain active until the end of your current billing cycle."},
|
| 24 |
+
{"customer_query": "Can I upgrade my account to the Pro tier?", "historical_resolution": "Yes, you can upgrade at any time. Go to your Account Settings, select 'Upgrade Plan', and choose the Pro tier. The prorated amount will be charged to your card immediately."},
|
| 25 |
+
{"customer_query": "My application keeps crashing on startup.", "historical_resolution": "Please ensure you are running the latest version of the app. Try clearing your browser cache. If the issue persists, please reply with your device OS and error logs."}
|
| 26 |
+
]
|
| 27 |
+
df = pd.DataFrame(backup_data)
|
| 28 |
|
| 29 |
print("2. Loading Embedding Model & Vectorizing Data...")
|
| 30 |
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
|
| 31 |
+
# Use the available rows (up to 100 for speed)
|
| 32 |
sample_resolutions = df['historical_resolution'].head(100).tolist()
|
| 33 |
resolution_embeddings = model.encode(sample_resolutions)
|
| 34 |
|
| 35 |
print("3. Connecting to LLM...")
|
| 36 |
+
# This pulls the HF_TOKEN securely from the Spaces Settings > Secrets
|
| 37 |
hf_token = os.environ.get("HF_TOKEN")
|
| 38 |
client = InferenceClient(
|
| 39 |
model="meta-llama/Meta-Llama-3-8B-Instruct",
|
|
|
|
| 73 |
|
| 74 |
with gr.Row():
|
| 75 |
with gr.Column():
|
| 76 |
+
# Hint updated to reflect the fallback dataset topics
|
| 77 |
+
input_query = gr.Textbox(lines=4, label="Incoming Customer Ticket (Try asking about billing or passwords in German, Spanish, etc.)")
|
| 78 |
submit_btn = gr.Button("Resolve Ticket")
|
| 79 |
|
| 80 |
with gr.Column():
|