Spaces:
Running
Running
Create core/models.py
Browse files- core/models.py +15 -0
core/models.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
def query_hf_model(prompt: str, model: str = "microsoft/phi-3.5-mini-instruct") -> str:
|
| 4 |
+
api_url = f"https://api-inference.huggingface.co/models/{model}"
|
| 5 |
+
response = requests.post(api_url, headers={"Content-Type": "application/json"}, json={"inputs": prompt})
|
| 6 |
+
if response.status_code == 200:
|
| 7 |
+
try:
|
| 8 |
+
data = response.json()
|
| 9 |
+
if isinstance(data, list) and len(data) > 0 and "generated_text" in data[0]:
|
| 10 |
+
return data[0]["generated_text"].strip()
|
| 11 |
+
return data
|
| 12 |
+
except Exception:
|
| 13 |
+
return response.text
|
| 14 |
+
else:
|
| 15 |
+
return f"⚠️ Ошибка модели: {response.status_code} — {response.text}"
|