Spaces:
Sleeping
Sleeping
Upload assistant.py
Browse files- assistant.py +15 -0
assistant.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
+
|
4 |
+
API_TOKEN = os.getenv("HF_API_TOKEN") # Loaded from secret
|
5 |
+
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-large"
|
6 |
+
|
7 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
8 |
+
|
9 |
+
def chat_with_hf_bot(prompt):
|
10 |
+
payload = {"inputs": prompt}
|
11 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
12 |
+
if response.status_code == 200:
|
13 |
+
return response.json()[0]["generated_text"]
|
14 |
+
else:
|
15 |
+
return f"Error: {response.text}"
|