88# ← Move imports to module level (critical for patching!)
99# requests is now available as app.frontend.requests
1010
11+ import os
12+
13+ FASTAPI_URL = os .getenv ("FASTAPI_URL" , "http://localhost:8000" )
14+
1115
1216def make_prediction (payload : Dict [str , Any ]) -> str :
1317 """Helper to call prediction endpoint"""
1418 try :
15- response = requests .post ("http://localhost:8000 /predict" , json = payload )
19+ response = requests .post (f" { FASTAPI_URL } /predict" , json = payload )
1620
1721 if response .status_code == 200 :
1822 score = response .json ()["predicted_success_score" ]
@@ -27,7 +31,7 @@ def ask_question(question: str) -> str:
2731 """Helper to call RAG endpoint"""
2832 try :
2933 response = requests .post (
30- "http://localhost:8000/ ask" , json = {"question" : question }
34+ response = requests . post ( f" { FASTAPI_URL } / ask" , json = {"question" : question })
3135 )
3236
3337 if response .status_code == 200 :
@@ -110,13 +114,11 @@ def main():
110114 answer = ask_question (user_input )
111115 st .session_state .messages .append ({"role" : "bot" , "content" : answer })
112116
113- for msg in st .session_state .messages :
117+ for i , msg in enumerate ( st .session_state .messages ) :
114118 if msg ["role" ] == "user" :
115- message (
116- msg ["content" ], is_user = True , key = str (hash (msg ["content" ] + "user" ))
117- )
119+ message (msg ["content" ], is_user = True , key = f"user_{ i } " )
118120 else :
119- message (msg ["content" ], key = str ( hash ( msg [ "content" ] + "bot" )) )
121+ message (msg ["content" ], is_user = False , key = f"bot_ { i } " )
120122
121123
122124if __name__ == "__main__" :
0 commit comments