AIcareerCoach / assistant.py
Hyma7's picture
Upload assistant.py
b3d4a72 verified
raw
history blame contribute delete
503 Bytes
import requests
import os
API_TOKEN = os.getenv("HF_API_TOKEN") # Loaded from secret
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-large"
headers = {"Authorization": f"Bearer {API_TOKEN}"}
def chat_with_hf_bot(prompt):
payload = {"inputs": prompt}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
return response.json()[0]["generated_text"]
else:
return f"Error: {response.text}"