Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,23 +18,27 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
| 18 |
# -------------------------
|
| 19 |
|
| 20 |
# You can change this to any instruct model you like
|
| 21 |
-
HF_MODEL_ID = "
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# If you use a private token, set it as HF_TOKEN env var in Spaces
|
| 24 |
client = InferenceClient(HF_MODEL_ID, token=os.getenv("HF_TOKEN"))
|
| 25 |
|
| 26 |
|
| 27 |
def get_llm():
|
| 28 |
-
|
| 29 |
|
| 30 |
def _llm(prompt: str) -> str:
|
|
|
|
| 31 |
response = client.text_generation(
|
| 32 |
prompt,
|
| 33 |
-
max_new_tokens=
|
| 34 |
-
temperature=0.
|
|
|
|
| 35 |
)
|
| 36 |
return response
|
| 37 |
-
|
| 38 |
return _llm
|
| 39 |
|
| 40 |
|
|
|
|
| 18 |
# -------------------------
|
| 19 |
|
| 20 |
# You can change this to any instruct model you like
|
| 21 |
+
HF_MODEL_ID = "ibm-granite/granite-3.1-8b-instruct"
|
| 22 |
+
|
| 23 |
+
# Option B: Llama 3.3 (Current industry standard)
|
| 24 |
+
# HF_MODEL_ID = "meta-llama/Llama-3.3-70B-Instruct"
|
| 25 |
|
| 26 |
# If you use a private token, set it as HF_TOKEN env var in Spaces
|
| 27 |
client = InferenceClient(HF_MODEL_ID, token=os.getenv("HF_TOKEN"))
|
| 28 |
|
| 29 |
|
| 30 |
def get_llm():
|
| 31 |
+
token = os.getenv("HF_TOKEN")
|
| 32 |
|
| 33 |
def _llm(prompt: str) -> str:
|
| 34 |
+
# We add wait_for_model to wake up the API if it's sleeping
|
| 35 |
response = client.text_generation(
|
| 36 |
prompt,
|
| 37 |
+
max_new_tokens=512,
|
| 38 |
+
temperature=0.1,
|
| 39 |
+
wait_for_model=True
|
| 40 |
)
|
| 41 |
return response
|
|
|
|
| 42 |
return _llm
|
| 43 |
|
| 44 |
|