Spaces:
Sleeping
Sleeping
Hotfix: Gemini 404 and enhanced error visibility
Browse files
app.py
CHANGED
|
@@ -54,10 +54,16 @@ def load_all_models():
|
|
| 54 |
try:
|
| 55 |
# ๋ชจ๋ธ ๋ค์ด๋ก๋ ๋ฐ ๋ก๋
|
| 56 |
cached_model = hf_hub_download(repo_id=REPO_ID, filename=self.model_path, repo_type="space")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
self.model = tf.keras.models.load_model(cached_model, compile=False)
|
| 58 |
self.load_error = "์ฑ๊ณต"
|
| 59 |
except Exception as model_e:
|
| 60 |
-
self.load_error = f"๋ชจ๋ธ
|
| 61 |
except Exception as e:
|
| 62 |
self.load_error = f"HuggingFace ๋ฆฌ์์ค ๋ก๋ ํตํฉ ์๋ฌ: {e}"
|
| 63 |
|
|
@@ -92,7 +98,13 @@ def load_all_models():
|
|
| 92 |
class Consultant:
|
| 93 |
def __init__(self):
|
| 94 |
api_key = os.getenv("GOOGLE_API_KEY", "")
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
self.embedding_model = None
|
| 97 |
self.retriever = None
|
| 98 |
|
|
@@ -147,7 +159,8 @@ def handle_predict(*args):
|
|
| 147 |
|
| 148 |
res = _models["predictor"].predict(features_dict)
|
| 149 |
if isinstance(res, str) and "Error" in res:
|
| 150 |
-
|
|
|
|
| 151 |
|
| 152 |
score_val = str(int(round(float(res))))
|
| 153 |
return {"features": features_dict, "score": score_val}, score_val
|
|
|
|
| 54 |
try:
|
| 55 |
# ๋ชจ๋ธ ๋ค์ด๋ก๋ ๋ฐ ๋ก๋
|
| 56 |
cached_model = hf_hub_download(repo_id=REPO_ID, filename=self.model_path, repo_type="space")
|
| 57 |
+
# [์ถ๊ฐ] ํ์ผ ํฌ๊ธฐ ํ์ธ ๋ก๊ทธ (๋๋ฒ๊น
์ฉ)
|
| 58 |
+
fsize = os.path.getsize(cached_model)
|
| 59 |
+
if fsize < 1000:
|
| 60 |
+
self.load_error = f"ํ์ผ์ด ๋๋ฌด ์์({fsize}B). LFS ํฌ์ธํฐ์ผ ๊ฐ๋ฅ์ฑ ์์."
|
| 61 |
+
return
|
| 62 |
+
|
| 63 |
self.model = tf.keras.models.load_model(cached_model, compile=False)
|
| 64 |
self.load_error = "์ฑ๊ณต"
|
| 65 |
except Exception as model_e:
|
| 66 |
+
self.load_error = f"๋ชจ๋ธ ๋ก๋ ์คํจ: {str(model_e)}\n{traceback.format_exc()}"
|
| 67 |
except Exception as e:
|
| 68 |
self.load_error = f"HuggingFace ๋ฆฌ์์ค ๋ก๋ ํตํฉ ์๋ฌ: {e}"
|
| 69 |
|
|
|
|
| 98 |
class Consultant:
|
| 99 |
def __init__(self):
|
| 100 |
api_key = os.getenv("GOOGLE_API_KEY", "")
|
| 101 |
+
# [์์ ] ๋ชจ๋ธ ๋ช
์นญ ๋ฐ API ๋ฒ์ ํธํ์ฑ ๊ณ ๋ ค
|
| 102 |
+
self.llm = ChatGoogleGenerativeAI(
|
| 103 |
+
model="gemini-1.5-flash",
|
| 104 |
+
google_api_key=api_key,
|
| 105 |
+
temperature=0.7,
|
| 106 |
+
convert_system_message_to_human=True
|
| 107 |
+
)
|
| 108 |
self.embedding_model = None
|
| 109 |
self.retriever = None
|
| 110 |
|
|
|
|
| 159 |
|
| 160 |
res = _models["predictor"].predict(features_dict)
|
| 161 |
if isinstance(res, str) and "Error" in res:
|
| 162 |
+
# ์๋ฌ ๋ฐ์ ์ UI ์๋จ ์ ์์นธ์ ์๋ฌ ๋ด์ฉ ๋๋ ๋
ธ์ถ (์ง๋ฒ ํ์ธ์ฉ)
|
| 163 |
+
return f"โ ๋ถ์ ์คํจ: {res}", f"โ ๏ธ {res[:100]}..."
|
| 164 |
|
| 165 |
score_val = str(int(round(float(res))))
|
| 166 |
return {"features": features_dict, "score": score_val}, score_val
|