BlakeL commited on
Commit
a023107
·
verified ·
1 Parent(s): 0b0792d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -25,6 +25,11 @@ import gradio as gr
25
  from datetime import datetime
26
  import json
27
 
 
 
 
 
 
28
  # Add the src directory to the path
29
  sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
30
 
@@ -100,8 +105,24 @@ except ImportError as e:
100
  class AuthenticationError(Exception):
101
  pass
102
 
103
- # Import the real API chat system for Hugging Face deployment
104
- from conversational_travel_chat_real_apis import RealAPIConversationalTravelChat
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  # Set up logging
107
  logging.basicConfig(
 
25
  from datetime import datetime
26
  import json
27
 
28
+ # Ensure the app directory itself is importable (for HF runtime quirks)
29
+ APP_DIR = os.path.dirname(__file__)
30
+ if APP_DIR not in sys.path:
31
+ sys.path.insert(0, APP_DIR)
32
+
33
  # Add the src directory to the path
34
  sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
35
 
 
105
  class AuthenticationError(Exception):
106
  pass
107
 
108
+ # Import the real API chat system for Hugging Face deployment (robust fallback)
109
+ try:
110
+ from conversational_travel_chat_real_apis import RealAPIConversationalTravelChat
111
+ except ModuleNotFoundError as e:
112
+ logger.warning(f"Primary import failed: {e}. sys.path={sys.path}")
113
+ # Attempt dynamic import via importlib as a fallback
114
+ try:
115
+ import importlib.util
116
+ module_path = os.path.join(APP_DIR, 'conversational_travel_chat_real_apis.py')
117
+ spec = importlib.util.spec_from_file_location('conversational_travel_chat_real_apis', module_path)
118
+ module = importlib.util.module_from_spec(spec)
119
+ assert spec and spec.loader
120
+ spec.loader.exec_module(module)
121
+ RealAPIConversationalTravelChat = getattr(module, 'RealAPIConversationalTravelChat')
122
+ logger.info("Loaded RealAPIConversationalTravelChat via dynamic import")
123
+ except Exception as inner_e:
124
+ logger.error(f"Failed to load conversational_travel_chat_real_apis: {inner_e}")
125
+ raise
126
 
127
  # Set up logging
128
  logging.basicConfig(