MaziyarPanahi commited on
Commit
bcd8178
1 Parent(s): 17b76bb

new update

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-39.pyc +0 -0
  2. 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
- for line in response.iter_lines():
170
- # Filter out keep-alive new lines
171
- if line:
172
- data = line.decode("utf-8").lstrip("data: ")
173
- # Check if the examples are valid
174
- valid_check = is_valid_json(data)
175
- if valid_check[0]:
176
- try:
177
- # Attempt to parse the JSON dataa
178
- # json_data = json.loads(data)
179
- json_data = valid_check[1]
180
-
181
- delta_content = (
182
- json_data.get("choices", [{}])[0]
183
- .get("delta", {})
184
- .get("content", "")
185
- )
186
-
187
- if delta_content: # Ensure there's content to print
188
- history[-1][1] += delta_content
189
- time.sleep(0.05)
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