Skip to content

RAG Based RBAS for chatbot #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pip install streamlit
import streamlit as st
import requests

# --- Streamlit Page Config ---
st.set_page_config(
page_title="FinSolve",
page_icon="🤖",
layout="wide"
)

# --- Sidebar: User Authentication and Role Selection ---
st.sidebar.title("📅 User Panel")
st.sidebar.subheader("Login")

username = st.sidebar.text_input("Username")
role = st.sidebar.selectbox("Select Role", [
"Employee", "Finance", "Marketing", "HR", "Engineering", "C-Level"
])
authenticate = st.sidebar.button("Login")

# Simulate authentication
session_state = st.session_state
if 'authenticated' not in session_state:
session_state.authenticated = False
if 'chat_history' not in session_state:
session_state.chat_history = []

if authenticate:
if username:
session_state.authenticated = True
session_state.username = username
session_state.role = role
else:
st.sidebar.warning("Please enter a username.")

# --- Main Chat Interface ---
st.title("🌐 FinSolve Role-Based AI Chatbot")

if session_state.authenticated:
st.success(f"Welcome, {session_state.username} ({session_state.role})")

user_input = st.text_input("Ask a question:", placeholder="e.g., Show me the Q2 financial report...")
ask_button = st.button("Send")

chat_area = st.container()

if ask_button and user_input:
# Display user query
session_state.chat_history.append(("user", user_input))

# --- Simulated Backend Request ---
with st.spinner("Processing your query..."):
response = requests.post(
"http://localhost:8000/query",
json={
"user": session_state.username,
"role": session_state.role,
"query": user_input
}
)

if response.status_code == 200:
result = response.json()
session_state.chat_history.append(("bot", result['response']))
else:
session_state.chat_history.append(("bot", "Error fetching response from server."))

# --- Display Chat History ---
with chat_area:
for sender, msg in session_state.chat_history:
if sender == "user":
st.markdown(f"**You:** {msg}")
else:
st.markdown(f"**Chatbot:** {msg}")

else:
st.warning("Please log in using the sidebar to access the chatbot.")

# --- Footer ---
st.markdown("---")
st.markdown("Built by FinSolve AI Engineering | © 2025")
# After code is executed,
#streamlit run "path of saved file"
Loading