Update app.py
Browse files
app.py
CHANGED
|
@@ -14,23 +14,18 @@ from transformers import pipeline
|
|
| 14 |
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
-
|
| 18 |
-
self.
|
| 19 |
-
"
|
| 20 |
-
|
| 21 |
-
framework="pt" # Explicitly use PyTorch
|
| 22 |
-
)
|
| 23 |
|
| 24 |
def __call__(self, question: str) -> str:
|
| 25 |
-
print(f"⚙️ Generating answer for: {question[:60]}...")
|
| 26 |
try:
|
| 27 |
-
response = self.
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
return
|
| 31 |
-
|
| 32 |
-
print(f"❌ Error in model inference: {e}")
|
| 33 |
-
return "Model error"
|
| 34 |
|
| 35 |
|
| 36 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 14 |
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
+
self.api_url = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
|
| 18 |
+
self.headers = {
|
| 19 |
+
"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"
|
| 20 |
+
}
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def __call__(self, question: str) -> str:
|
|
|
|
| 23 |
try:
|
| 24 |
+
response = requests.post(self.api_url, headers=self.headers, json={"inputs": question})
|
| 25 |
+
return response.json()[0]["generated_text"].strip()
|
| 26 |
+
except:
|
| 27 |
+
return "API error"
|
| 28 |
+
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|