Spaces:
Runtime error
Runtime error
File size: 1,515 Bytes
e68d535 |
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 |
import streamlit as st
import requests
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
def handle_enter():
st.session_state['submitted'] = True
if __name__ == "__main__":
# Streamlit UI
st.title("RFP Q/A")
# Sidebar for settings
with st.sidebar:
st.title("Settings")
st.divider()
protect_enabled = st.toggle("Galileo Protect", value=False,
help="Enable content protection with Galileo")
# Callback function when Enter is pressed
def on_enter():
st.session_state["run_search"] = True
# User input
st.text_input("Ask your question:", key="query", on_change=on_enter)
# Search button
if st.button("Search"):
st.session_state["run_search"] = True
# Run the search if triggered by button or Enter
if st.session_state.get("run_search"):
try:
query = st.session_state.get("query", "").strip()
# Make request to FastAPI endpoint
response = requests.post(
"http://localhost:8000/rag/search",
json={"query": query, "protect_enabled": protect_enabled}
)
if response.status_code == 200:
result = response.json()
st.success("Search Results:")
st.write(result["response"])
else:
st.error(f"Error: {response.text}")
except Exception as e:
st.error(f"Error: {str(e)}")
|