siddani93 commited on
Commit
d12cc26
·
verified ·
1 Parent(s): 47781e6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import google.generativeai as genai
4
+
5
+ # Configure Gemini
6
+ GEMINI_API_KEY = os.getenv('GEMINI_API_KEY') # Set in Hugging Face secrets
7
+ genai.configure(api_key=GEMINI_API_KEY)
8
+ model = genai.GenerativeModel('gemini-pro')
9
+
10
+ # Industry Knowledge Base
11
+ INDUSTRY_KNOWLEDGE = """
12
+ **Refunds:**
13
+ - Refund processing time: 5-7 business days
14
+ - Request refunds by contacting support with order number
15
+ - Refunds issued to original payment method
16
+
17
+ **Invoices:**
18
+ - Invoices generated immediately after purchase
19
+ - Download from account dashboard
20
+ - Corrections: email billing@company.com
21
+
22
+ **Shipments:**
23
+ - Standard shipping: 3-5 days
24
+ - Express shipping: 1-2 days
25
+ - Track using link in confirmation email
26
+ """
27
+
28
+ SYSTEM_PROMPT = f"""
29
+ You are an AI customer support specialist. Use this knowledge to answer questions:
30
+
31
+ {INDUSTRY_KNOWLEDGE}
32
+
33
+ Guidelines:
34
+ 1. Be professional and helpful
35
+ 2. For unknown answers: "I'll connect you with a human representative"
36
+ 3. Keep responses concise
37
+ 4. Ask for order numbers for account-specific issues
38
+ """
39
+
40
+ # Initialize chat history
41
+ if "messages" not in st.session_state:
42
+ st.session_state.messages = []
43
+
44
+ # Streamlit UI
45
+ st.title("Industry FAQ Assistant 🤖")
46
+ st.caption("24/7 AI Support for Refunds, Invoices, and Shipments")
47
+
48
+ # Display chat messages
49
+ for message in st.session_state.messages:
50
+ with st.chat_message(message["role"]):
51
+ st.markdown(message["content"])
52
+
53
+ # Chat input
54
+ if prompt := st.chat_input("Ask your question..."):
55
+ # Add user message to chat history
56
+ st.session_state.messages.append({"role": "user", "content": prompt})
57
+
58
+ # Display user message
59
+ with st.chat_message("user"):
60
+ st.markdown(prompt)
61
+
62
+ # Generate response
63
+ try:
64
+ full_prompt = f"{SYSTEM_PROMPT}\n\nQuestion: {prompt}"
65
+ response = model.generate_content(full_prompt)
66
+ answer = response.text
67
+
68
+ # Display assistant response
69
+ with st.chat_message("assistant"):
70
+ st.markdown(answer)
71
+
72
+ # Add assistant response to chat history
73
+ st.session_state.messages.append({"role": "assistant", "content": answer})
74
+
75
+ except Exception as e:
76
+ st.error(f"Error generating response: {str(e)}")