Spaces:
Runtime error
Runtime error
File size: 4,004 Bytes
d72adbe 33bb7de d72adbe 33bb7de d1e8d6f d72adbe 33bb7de d72adbe 33bb7de d72adbe d1e8d6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | # streamlit_app.py
import streamlit as st
from Customer_Support.workflow import run_customer_support
# Set page configuration
st.set_page_config(
page_title="Customer Support Assistant",
page_icon="π¬",
layout="centered"
)
# Title and description
st.title("Customer Support Assistant")
st.markdown("Ask a question about technical issues, billing, or general inquiries.")
# API endpoint (change this if your FastAPI app is running on a different address)
#API_URL = "http://127.0.0.1:8000/process"
# "https://amna2024-customer-support-assistant.hf.space/process"
# Create a function to call the API
#def process_query(query):
# try:
# response = requests.post(
# API_URL,
# json={"query": query},
# headers={"Content-Type": "application/json"},
# timeout=10
# )
# return response.json()
# except requests.exceptions.RequestException as e:
# return {"error": f"API request failed: {str(e)}"}
# Create the main interface
query = st.text_area("What can I help you with today?", height=100)
submit_button = st.button("Submit")
# Display previous conversation if available
if "conversation" not in st.session_state:
st.session_state.conversation = []
# Process input when the button is clicked
if submit_button and query:
with st.spinner("Processing your request..."):
# Call the API
#result = process_query(query)
result = run_customer_support(query)
st.write("π§ Raw response:", result) # π Add this line for debugging
if "error" in result:
st.error(result["error"])
else:
# Add the query and response to the conversation history
st.session_state.conversation.append({
"query": query,
"category": result.get("category", "Unknown"),
"sentiment": result.get("sentiment", "Unknown"),
"response": result.get("response", "Sorry, I couldn't process your request.")
})
# Clear the input area after submission
st.rerun()
# Display conversation history in reverse order (newest first)
if st.session_state.conversation:
st.markdown("### Conversation History")
for i, interaction in enumerate(reversed(st.session_state.conversation)):
# Create an expandable section for each interaction
with st.expander(f"Query: {interaction['query'][:50]}...", expanded=(i == 0)):
st.markdown(f"**Category**: {interaction['category']}")
st.markdown(f"**Sentiment**: {interaction['sentiment']}")
# Display the response in a colored box based on sentiment
sentiment_color = {
"Positive": "rgba(0, 180, 0, 0.1)",
"Neutral": "rgba(100, 100, 100, 0.1)",
"Negative": "rgba(255, 0, 0, 0.1)"
}.get(interaction['sentiment'], "rgba(100, 100, 100, 0.1)")
st.markdown(
f"""
<div style="background-color: {sentiment_color}; padding: 15px; border-radius: 5px;">
{interaction['response']}
</div>
""",
unsafe_allow_html=True
)
# Add a sidebar with some helpful information
with st.sidebar:
st.header("About")
st.markdown("""
This Customer Support Assistant uses AI to:
- Categorize your query (Technical, Billing, General)
- Analyze sentiment
- Provide relevant support responses
Try asking questions about:
- Technical issues with products or services
- Billing inquiries or problems
- General information requests
""")
# Add a health check indicator
#try:
# health_response = requests.get("http://localhost:8000/health")
# if health_response.status_code == 200:
# st.success("β
API is online")
# else:
# st.error("β API is having issues")
#except:
# st.error("β Could not connect to API") |