Spaces:
Sleeping
Sleeping
Update model_api.py
Browse files- model_api.py +17 -6
model_api.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import requests
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
load_dotenv()
|
| 6 |
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def query_model(prompt):
|
| 11 |
payload = {
|
|
@@ -17,4 +18,14 @@ def query_model(prompt):
|
|
| 17 |
}
|
| 18 |
|
| 19 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import time
|
|
|
|
|
|
|
| 4 |
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
|
| 6 |
+
|
| 7 |
+
headers = {
|
| 8 |
+
"Authorization": f"Bearer {st.secrets['HF_TOKEN']}"
|
| 9 |
+
}
|
| 10 |
|
| 11 |
def query_model(prompt):
|
| 12 |
payload = {
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
response = requests.post(API_URL, headers=headers, json=payload)
|
| 21 |
+
result = response.json()
|
| 22 |
+
|
| 23 |
+
# If model is loading
|
| 24 |
+
if isinstance(result, dict) and "error" in result:
|
| 25 |
+
return f"⚠ Model Error: {result['error']}"
|
| 26 |
+
|
| 27 |
+
# If normal success response
|
| 28 |
+
if isinstance(result, list) and len(result) > 0:
|
| 29 |
+
return result[0]["generated_text"]
|
| 30 |
+
|
| 31 |
+
return "Unexpected response from model."
|