mimifuel2018 commited on
Commit
5990a55
·
verified ·
1 Parent(s): 6619634

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
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('HF_TOKEN')}"}
66
 
67
  try:
68
  # Request generation with Hugging Face Inference API
69
- response = requests.post(f"https://api-inference.huggingface.co/models/Qwen/Qwen2.5-72B-Instruct",
70
  json=payload, headers=headers)
71
 
72
  if response.status_code == 200:
73
- response_text = response.json().get('generated_text', '')
 
 
 
 
 
 
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)