Spaces:
Sleeping
Sleeping
Empereur-Pirate
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -48,12 +48,16 @@ async def parse_raw(request: Request):
|
|
48 |
# Generate text using the Inference API
|
49 |
def generate_text(input_text: str) -> str:
|
50 |
data = {"inputs": input_text}
|
51 |
-
|
|
|
|
|
52 |
|
53 |
-
|
54 |
|
55 |
-
try:
|
56 |
return response.json()["generated_text"]
|
|
|
|
|
|
|
57 |
except KeyError as e:
|
58 |
print(f"KeyError: {e}. Check the response object for the correct key.")
|
59 |
return ""
|
|
|
48 |
# Generate text using the Inference API
|
49 |
def generate_text(input_text: str) -> str:
|
50 |
data = {"inputs": input_text}
|
51 |
+
try:
|
52 |
+
response = requests.post(endpoint, json=data, headers=headers)
|
53 |
+
response.raise_for_status() # Raise an exception for non-2xx status codes
|
54 |
|
55 |
+
print(response.json()) # Print the entire response object
|
56 |
|
|
|
57 |
return response.json()["generated_text"]
|
58 |
+
except requests.exceptions.RequestException as e:
|
59 |
+
print(f"RequestException: {e}")
|
60 |
+
return ""
|
61 |
except KeyError as e:
|
62 |
print(f"KeyError: {e}. Check the response object for the correct key.")
|
63 |
return ""
|