Spaces:
Sleeping
Sleeping
293droid commited on
Commit ·
91f67cd
1
Parent(s): b4470d5
fix: use SmolLM2-1.7B via HF Inference API - Tiny Titan eligible
Browse files- app.py +11 -6
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -11,6 +11,12 @@ from chemistry import (
|
|
| 11 |
calculate_lye, score_recipe, find_substitutes,
|
| 12 |
cure_timeline, profile_summary, list_oils, OILS
|
| 13 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# ---------------------------------------------------------------------------
|
| 16 |
# Config — change MODEL to "Qwen/Qwen2.5-7B-Instruct" on HF Space
|
|
@@ -88,19 +94,18 @@ def detect_mode(text: str) -> str:
|
|
| 88 |
# ---------------------------------------------------------------------------
|
| 89 |
|
| 90 |
def ask_model(prompt: str, context: str) -> str:
|
| 91 |
-
"""Call local Ollama model."""
|
| 92 |
full_prompt = f"{context}\n\nUser asked: {prompt}"
|
| 93 |
try:
|
| 94 |
-
response =
|
| 95 |
-
model=MODEL,
|
| 96 |
messages=[
|
| 97 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 98 |
{"role": "user", "content": full_prompt}
|
| 99 |
-
]
|
|
|
|
| 100 |
)
|
| 101 |
-
return response[
|
| 102 |
except Exception as e:
|
| 103 |
-
return f"Model error: {str(e)}
|
| 104 |
|
| 105 |
|
| 106 |
# ---------------------------------------------------------------------------
|
|
|
|
| 11 |
calculate_lye, score_recipe, find_substitutes,
|
| 12 |
cure_timeline, profile_summary, list_oils, OILS
|
| 13 |
)
|
| 14 |
+
import os
|
| 15 |
+
from huggingface_hub import InferenceClient
|
| 16 |
+
|
| 17 |
+
client = InferenceClient("HuggingFaceTB/SmolLM2-1.7B-Instruct")
|
| 18 |
+
|
| 19 |
+
MODEL = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
|
| 20 |
|
| 21 |
# ---------------------------------------------------------------------------
|
| 22 |
# Config — change MODEL to "Qwen/Qwen2.5-7B-Instruct" on HF Space
|
|
|
|
| 94 |
# ---------------------------------------------------------------------------
|
| 95 |
|
| 96 |
def ask_model(prompt: str, context: str) -> str:
|
|
|
|
| 97 |
full_prompt = f"{context}\n\nUser asked: {prompt}"
|
| 98 |
try:
|
| 99 |
+
response = client.chat_completion(
|
|
|
|
| 100 |
messages=[
|
| 101 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 102 |
{"role": "user", "content": full_prompt}
|
| 103 |
+
],
|
| 104 |
+
max_tokens=500,
|
| 105 |
)
|
| 106 |
+
return response.choices[0].message.content
|
| 107 |
except Exception as e:
|
| 108 |
+
return f"Model error: {str(e)}"
|
| 109 |
|
| 110 |
|
| 111 |
# ---------------------------------------------------------------------------
|
requirements.txt
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
gradio
|
| 2 |
-
ollama
|
| 3 |
huggingface_hub
|
|
|
|
| 1 |
gradio
|
|
|
|
| 2 |
huggingface_hub
|