smgc commited on
Commit
bc4ed93
1 Parent(s): 3af6d28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -1,11 +1,10 @@
1
- from flask import Flask, request, jsonify, Response
2
  import requests
3
  import json
4
  import time
5
  import random
6
  import logging
7
  import sys
8
- import asyncio
9
 
10
  app = Flask(__name__)
11
 
@@ -155,18 +154,16 @@ def handle_request():
155
  image_data = {'data': [{'url': image_url}]}
156
 
157
  if stream:
158
- return stream_response(request, unique_id, image_data, prompt, enhanced_prompt, "1024x1024", current_timestamp, model, system_fingerprint)
159
  else:
160
  return non_stream_response(unique_id, image_data, prompt, enhanced_prompt, "1024x1024", current_timestamp, model, system_fingerprint)
161
  except Exception as e:
162
  logger.error(f"Unexpected error in handle_request: {str(e)}")
163
  return jsonify({"error": f"Internal Server Error: {str(e)}"}), 500
164
 
165
- def stream_response(request, unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint):
166
  logger.debug("Starting stream response")
167
- response = Response(stream_with_context(generate_stream(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint)), content_type='text/event-stream')
168
- logger.debug("Stream response completed")
169
- return response
170
 
171
  def generate_stream(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint):
172
  chunks = [
 
1
+ from flask import Flask, request, jsonify, Response, stream_with_context
2
  import requests
3
  import json
4
  import time
5
  import random
6
  import logging
7
  import sys
 
8
 
9
  app = Flask(__name__)
10
 
 
154
  image_data = {'data': [{'url': image_url}]}
155
 
156
  if stream:
157
+ return stream_response(unique_id, image_data, prompt, enhanced_prompt, "1024x1024", current_timestamp, model, system_fingerprint)
158
  else:
159
  return non_stream_response(unique_id, image_data, prompt, enhanced_prompt, "1024x1024", current_timestamp, model, system_fingerprint)
160
  except Exception as e:
161
  logger.error(f"Unexpected error in handle_request: {str(e)}")
162
  return jsonify({"error": f"Internal Server Error: {str(e)}"}), 500
163
 
164
+ def stream_response(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint):
165
  logger.debug("Starting stream response")
166
+ return Response(stream_with_context(generate_stream(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint)), content_type='text/event-stream')
 
 
167
 
168
  def generate_stream(unique_id, image_data, original_prompt, translated_prompt, size, created, model, system_fingerprint):
169
  chunks = [