# 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"""