MaziyarPanahi
commited on
Commit
•
bcd8178
1
Parent(s):
17b76bb
new update
Browse files- __pycache__/app.cpython-39.pyc +0 -0
- app.py +22 -24
__pycache__/app.cpython-39.pyc
CHANGED
Binary files a/__pycache__/app.cpython-39.pyc and b/__pycache__/app.cpython-39.pyc differ
|
|
app.py
CHANGED
@@ -165,31 +165,29 @@ with gr.Blocks() as demo:
|
|
165 |
)
|
166 |
if response.status_code == 200:
|
167 |
for line in response.iter_lines():
|
|
|
168 |
if line:
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
yield history
|
191 |
-
except json.JSONDecodeError as e:
|
192 |
-
print(f"Error decoding JSON: {e} date: {data}")
|
193 |
except requests.exceptions.RequestException as e:
|
194 |
print(f"An error occurred: {e}")
|
195 |
|
|
|
165 |
)
|
166 |
if response.status_code == 200:
|
167 |
for line in response.iter_lines():
|
168 |
+
# Filter out keep-alive new lines
|
169 |
if line:
|
170 |
+
data = line.decode("utf-8").lstrip("data: ")
|
171 |
+
# Check if the examples are valid
|
172 |
+
valid_check = is_valid_json(data)
|
173 |
+
if valid_check[0]:
|
174 |
+
try:
|
175 |
+
# Attempt to parse the JSON dataa
|
176 |
+
# json_data = json.loads(data)
|
177 |
+
json_data = valid_check[1]
|
178 |
+
|
179 |
+
delta_content = (
|
180 |
+
json_data.get("choices", [{}])[0]
|
181 |
+
.get("delta", {})
|
182 |
+
.get("content", "")
|
183 |
+
)
|
184 |
+
|
185 |
+
if delta_content: # Ensure there's content to print
|
186 |
+
history[-1][1] += delta_content
|
187 |
+
time.sleep(0.05)
|
188 |
+
yield history
|
189 |
+
except json.JSONDecodeError as e:
|
190 |
+
print(f"Error decoding JSON: {e} date: {data}")
|
|
|
|
|
|
|
191 |
except requests.exceptions.RequestException as e:
|
192 |
print(f"An error occurred: {e}")
|
193 |
|