Spaces:
Build error
Build error
File size: 790 Bytes
8b15eea 5f311b3 8b15eea 5f311b3 8b15eea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import requests
from os import getenv
API_URL = getenv('API_URL')
BEARER = getenv('BEARER')
headers = {
"Authorization": f"Bearer {BEARER}",
"Content-Type": "application/json"
}
def call_jais(payload):
try:
response = requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status() # This will raise an exception for HTTP error codes
return response.json()
except requests.exceptions.HTTPError as http_err:
raise gr.Error(f"An error occurred while processing the request. {http_err}")
except Exception as err:
raise gr.Error(f"An error occurred while processing the request. {err}")
def generate(prompt: str):
payload = {'inputs': '', 'prompt':prompt}
response = call_jais(payload)
return response |