Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,15 +62,21 @@ def model_chat(query: Optional[str], history: Optional[History], system: str) ->
|
|
62 |
|
63 |
# Prepare the payload for Hugging Face Inference API
|
64 |
payload = {"inputs": query, "parameters": {"max_new_tokens": 150}, "history": messages}
|
65 |
-
headers = {"Authorization": f"Bearer {os.getenv('
|
66 |
|
67 |
try:
|
68 |
# Request generation with Hugging Face Inference API
|
69 |
-
response = requests.post(f"https://api-inference.huggingface.co/models/
|
70 |
json=payload, headers=headers)
|
71 |
|
72 |
if response.status_code == 200:
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Log the chat to file
|
76 |
log_history_to_file(query, response_text)
|
|
|
62 |
|
63 |
# Prepare the payload for Hugging Face Inference API
|
64 |
payload = {"inputs": query, "parameters": {"max_new_tokens": 150}, "history": messages}
|
65 |
+
headers = {"Authorization": f"Bearer {os.getenv('YOUR_API_TOKEN')}"}
|
66 |
|
67 |
try:
|
68 |
# Request generation with Hugging Face Inference API
|
69 |
+
response = requests.post(f"https://api-inference.huggingface.co/models/YourModelNameHere",
|
70 |
json=payload, headers=headers)
|
71 |
|
72 |
if response.status_code == 200:
|
73 |
+
response_data = response.json()
|
74 |
+
|
75 |
+
# Handle the response as a list or dict
|
76 |
+
if isinstance(response_data, list):
|
77 |
+
response_text = response_data[0].get('generated_text', '')
|
78 |
+
else:
|
79 |
+
response_text = response_data.get('generated_text', '')
|
80 |
|
81 |
# Log the chat to file
|
82 |
log_history_to_file(query, response_text)
|