Spaces:
Sleeping
Sleeping
Update analytics/ai_assistant.py
Browse files
analytics/ai_assistant.py
CHANGED
|
@@ -126,6 +126,8 @@ def _get_inference_client():
|
|
| 126 |
"HUGGINGFACE_API_TOKEN is required for AI assistant. "
|
| 127 |
"Set it in your environment before running the app."
|
| 128 |
)
|
|
|
|
|
|
|
| 129 |
return InferenceClient(token=HF_TOKEN)
|
| 130 |
|
| 131 |
|
|
@@ -141,6 +143,7 @@ def generate_ai_answer(question: str, df: pd.DataFrame, as_of_month: str = None,
|
|
| 141 |
)
|
| 142 |
|
| 143 |
client = _get_inference_client()
|
|
|
|
| 144 |
response = client.text_generation(
|
| 145 |
model=HF_MODEL_ID,
|
| 146 |
prompt = prompt,
|
|
@@ -149,6 +152,7 @@ def generate_ai_answer(question: str, df: pd.DataFrame, as_of_month: str = None,
|
|
| 149 |
top_k= 50,
|
| 150 |
top_p= 0.95
|
| 151 |
)
|
|
|
|
| 152 |
|
| 153 |
if isinstance(response, dict):
|
| 154 |
return response.get("generated_text") or response.get("text") or str(response)
|
|
|
|
| 126 |
"HUGGINGFACE_API_TOKEN is required for AI assistant. "
|
| 127 |
"Set it in your environment before running the app."
|
| 128 |
)
|
| 129 |
+
else:
|
| 130 |
+
print("Inference set up successful.")
|
| 131 |
return InferenceClient(token=HF_TOKEN)
|
| 132 |
|
| 133 |
|
|
|
|
| 143 |
)
|
| 144 |
|
| 145 |
client = _get_inference_client()
|
| 146 |
+
print("Inference called successfully")
|
| 147 |
response = client.text_generation(
|
| 148 |
model=HF_MODEL_ID,
|
| 149 |
prompt = prompt,
|
|
|
|
| 152 |
top_k= 50,
|
| 153 |
top_p= 0.95
|
| 154 |
)
|
| 155 |
+
print(response)
|
| 156 |
|
| 157 |
if isinstance(response, dict):
|
| 158 |
return response.get("generated_text") or response.get("text") or str(response)
|