mali08890 commited on
Commit
33be09b
Β·
verified Β·
1 Parent(s): 7a07ff6

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +10 -0
  2. app.py +119 -0
  3. gitattributes +35 -0
  4. requirements.txt +6 -0
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Cinco Return Chatbot
3
+ emoji: πŸ€–
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: "3.50.2"
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
app.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
3
+
4
+ # Load a lightweight, CPU-friendly model
5
+ model_id = "google/flan-t5-base"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
8
+
9
+ # Pipeline setup
10
+ chatbot = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
11
+
12
+ # Function to format prompt for chat-like interaction
13
+ #def format_prompt(history, user_input):
14
+ # base_prompt = (
15
+ # "You are Cinco, a helpful and friendly customer support assistant. "
16
+ # "Answer customer questions politely and clearly about product returns, refunds, and exchanges.\n\n"
17
+ #)
18
+ #for user, bot in history:
19
+ # base_prompt += f"Customer: {user}\nCinco Assistant: {bot}\n"
20
+ #base_prompt += f"Customer: {user_input}\nCinco Assistant:"
21
+ #return base_prompt
22
+
23
+ def format_prompt(history, user_input):
24
+ policy_context = (
25
+ "Cinco Return Policy Guidelines:\n"
26
+ "- πŸ•’ **Returns Window**: Items may be returned **within 30 days** from the date of purchase.\n"
27
+ "- 🧾 **Proof of Purchase**: A **valid receipt or order confirmation** is required for all returns and refunds.\n"
28
+ "- πŸ“¦ **Item Condition**: Returned products must be in **original condition**, meaning **unused, unwashed, with tags still attached**.\n"
29
+ "- πŸ’³ **Refunds**: Refunds will be processed to the **original method of payment** (e.g., credit card, debit card, PayPal).\n"
30
+ "- πŸ” **Exchanges**: Each item is eligible for **a one-time exchange only**, subject to availability.\n"
31
+ "- 🚫 **Non-Returnable Items**: Items that have been **used, washed, or worn**, or returned **without a receipt**, **cannot be accepted** for return or exchange.\n"
32
+ "- 🎁 **Gifts**: Gift returns require a **gift receipt** and will be refunded via **Cinco gift card**.\n"
33
+ "- 🌐 **Online Orders**: For items bought online, customers can return via **mail** or in **any Cinco retail store** with a printed invoice.\n"
34
+ "- βŒ› **Processing Time**: Please allow **5–7 business days** after the item is received for the refund to reflect.\n"
35
+ "- πŸ›οΈ **Final Sale Items**: Some products (e.g., clearance or promotional items) are marked as **final sale** and are **not eligible** for return or exchange.\n\n"
36
+ )
37
+
38
+
39
+ intro = "You are Cinco Assistant, a helpful and polite customer support agent for the clothing brand Cinco.\n"
40
+
41
+ # Include history if any
42
+ formatted_history = ""
43
+ if history:
44
+ for i, (user_q, bot_a) in enumerate(history):
45
+ formatted_history += f"Customer: {user_q}\nCinco Assistant: {bot_a}\n"
46
+
47
+ current_question = f"Customer: {user_input}\nCinco Assistant:"
48
+
49
+ # Combine everything
50
+ prompt = (
51
+ intro
52
+ + policy_context
53
+ + "Use the above return policy to answer the customer's question below.\n\n"
54
+ + formatted_history
55
+ + current_question
56
+ )
57
+
58
+ return prompt
59
+
60
+
61
+ # Chatbot logic
62
+ def chat_fn(user_input, history):
63
+ history = history or []
64
+ prompt = format_prompt(history, user_input)
65
+ response = chatbot(prompt, max_length=256, do_sample=False, clean_up_tokenization_spaces=True)[0]["generated_text"]
66
+
67
+ if "Cinco Assistant:" in response:
68
+ assistant_reply = response.split("Cinco Assistant:")[-1].strip()
69
+ else:
70
+ assistant_reply = response.strip()
71
+
72
+ history.append((user_input, assistant_reply))
73
+ return "", history, history # return history twice: one for state, one for Chatbot UI
74
+
75
+ # Enhanced UI with better layout and visuals
76
+ with gr.Blocks(title="Cinco Returns Chatbot") as demo:
77
+ gr.Markdown("""
78
+ # 🧾 Cinco Returns Chatbot
79
+ Welcome to the Cinco Returns Assistant. Ask your questions about returns, refunds, and exchanges.
80
+
81
+ ### πŸ’¬ Example Questions:
82
+ - *Can I return a sweater I no longer want?*
83
+ - *What if I don’t have a receipt?*
84
+ - *Can I exchange a used item?*
85
+ """)
86
+
87
+ with gr.Box():
88
+ chatbot_ui = gr.Chatbot(label="Cinco Assistant", show_label=False, height=400)
89
+
90
+ with gr.Row():
91
+ user_input = gr.Textbox(
92
+ placeholder="Type your question here (e.g., I want to return a sweater)...",
93
+ scale=9,
94
+ show_label=False,
95
+ lines=2
96
+ )
97
+ submit_btn = gr.Button("Send", variant="primary", scale=1)
98
+
99
+ state = gr.State([])
100
+
101
+ submit_btn.click(
102
+ fn=chat_fn,
103
+ inputs=[user_input, state],
104
+ outputs=[user_input, state, chatbot_ui] # return history to both state and Chatbot
105
+ )
106
+ user_input.submit(
107
+ fn=chat_fn,
108
+ inputs=[user_input, state],
109
+ outputs=[user_input, state, chatbot_ui]
110
+ )
111
+
112
+
113
+ gr.Markdown("""
114
+ ---
115
+ πŸ€– Powered by [FLAN-T5](https://huggingface.co/google/flan-t5-base) on Hugging Face Spaces.
116
+ """)
117
+
118
+ if __name__ == "__main__":
119
+ demo.launch()
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers==4.40.0
2
+ gradio==4.44.1
3
+ torch
4
+ faiss-cpu
5
+ sentence-transformers
6
+ accelerate>=0.26.0