88# ← Move imports to module level (critical for patching!)
99# requests is now available as app.frontend.requests
1010
11+ import os
12+ FASTAPI_URL = os .getenv ("FASTAPI_URL" , "http://localhost:8000" )
1113
1214def make_prediction (payload : Dict [str , Any ]) -> str :
1315 """Helper to call prediction endpoint"""
1416 try :
15- response = requests .post ("http://localhost:8000 /predict" , json = payload )
17+ response = requests .post (f" { FASTAPI_URL } /predict" , json = payload )
1618
1719 if response .status_code == 200 :
1820 score = response .json ()["predicted_success_score" ]
@@ -27,7 +29,7 @@ def ask_question(question: str) -> str:
2729 """Helper to call RAG endpoint"""
2830 try :
2931 response = requests .post (
30- "http://localhost:8000/ ask" , json = {"question" : question }
32+ response = requests . post ( f" { FASTAPI_URL } / ask" , json = {"question" : question })
3133 )
3234
3335 if response .status_code == 200 :
@@ -110,13 +112,11 @@ def main():
110112 answer = ask_question (user_input )
111113 st .session_state .messages .append ({"role" : "bot" , "content" : answer })
112114
113- for msg in st .session_state .messages :
115+ for i , msg in enumerate ( st .session_state .messages ) :
114116 if msg ["role" ] == "user" :
115- message (
116- msg ["content" ], is_user = True , key = str (hash (msg ["content" ] + "user" ))
117- )
117+ message (msg ["content" ], is_user = True , key = f"user_{ i } " )
118118 else :
119- message (msg ["content" ], key = str ( hash ( msg [ "content" ] + "bot" )) )
119+ message (msg ["content" ], is_user = False , key = f"bot_ { i } " )
120120
121121
122122if __name__ == "__main__" :
0 commit comments