Update app.py
Browse files
app.py
CHANGED
|
@@ -120,7 +120,7 @@ def stream_response(prompt_text, api_key):
|
|
| 120 |
Yields each chunk of text as it arrives.
|
| 121 |
"""
|
| 122 |
try:
|
| 123 |
-
|
| 124 |
payload = {
|
| 125 |
"inputs": prompt_text,
|
| 126 |
"parameters": {
|
|
@@ -129,14 +129,19 @@ def stream_response(prompt_text, api_key):
|
|
| 129 |
"stream": True
|
| 130 |
}
|
| 131 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
# POST request with stream=True to get partial chunks
|
| 134 |
response = requests.post(
|
| 135 |
SPACE_URL,
|
| 136 |
json=payload,
|
| 137 |
-
headers=
|
| 138 |
stream=True
|
| 139 |
-
)
|
| 140 |
response.raise_for_status()
|
| 141 |
|
| 142 |
# The endpoint presumably returns lines of JSON. Adjust parsing if needed:
|
|
|
|
| 120 |
Yields each chunk of text as it arrives.
|
| 121 |
"""
|
| 122 |
try:
|
| 123 |
+
# Match the structure of your working payload:
|
| 124 |
payload = {
|
| 125 |
"inputs": prompt_text,
|
| 126 |
"parameters": {
|
|
|
|
| 129 |
"stream": True
|
| 130 |
}
|
| 131 |
}
|
| 132 |
+
headers = {
|
| 133 |
+
"Accept" : "application/json",
|
| 134 |
+
"Authorization": f"Bearer {api_key}",
|
| 135 |
+
"Content-Type": "application/json"
|
| 136 |
+
}
|
| 137 |
|
| 138 |
# POST request with stream=True to get partial chunks
|
| 139 |
response = requests.post(
|
| 140 |
SPACE_URL,
|
| 141 |
json=payload,
|
| 142 |
+
headers=headers,
|
| 143 |
stream=True
|
| 144 |
+
))
|
| 145 |
response.raise_for_status()
|
| 146 |
|
| 147 |
# The endpoint presumably returns lines of JSON. Adjust parsing if needed:
|