yangtb24 commited on
Commit
429db12
·
verified ·
1 Parent(s): 7314969

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -113,6 +113,24 @@ def test_model_availability(api_key, model_name):
113
  f"API Key:{api_key},错误信息:{e}"
114
  )
115
  return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  def refresh_models():
118
  global text_models, free_text_models
@@ -838,8 +856,8 @@ def handsome_chat_completions():
838
  siliconflow_data = {
839
  "model": model_name,
840
  "prompt": user_content,
841
-
842
  }
 
843
  if model_name == "black-forest-labs/FLUX.1-pro":
844
  siliconflow_data["width"] = data.get("width", 1024)
845
  siliconflow_data["height"] = data.get("height", 768)
@@ -935,7 +953,7 @@ def handsome_chat_completions():
935
  image_url = images[0]
936
  logging.info(f"Extracted image URL: {image_url}")
937
 
938
- markdown_image_link = f"![image]({image_url})"
939
  if image_url:
940
  chunk_data = {
941
  "id": f"chatcmpl-{uuid.uuid4()}",
 
113
  f"API Key:{api_key},错误信息:{e}"
114
  )
115
  return False
116
+
117
+ def create_base64_markdown_image(image_url):
118
+ try:
119
+ response = requests.get(image_url, stream=True)
120
+ response.raise_for_status()=
121
+
122
+ image_data = response.content
123
+ base64_encoded = base64.b64encode(image_data).decode('utf-8')
124
+ mime_type = response.headers.get('Content-Type', 'image/png')
125
+ markdown_image_link = f"![image](data:{mime_type};base64,{base64_encoded})"
126
+ logging.info(f"Created base64 markdown image link.")
127
+ return markdown_image_link
128
+ except requests.exceptions.RequestException as e:
129
+ logging.error(f"Error downloading image: {e}")
130
+ return None
131
+ except Exception as e:
132
+ logging.error(f"Error during processing: {e}")
133
+ return None
134
 
135
  def refresh_models():
136
  global text_models, free_text_models
 
856
  siliconflow_data = {
857
  "model": model_name,
858
  "prompt": user_content,
 
859
  }
860
+
861
  if model_name == "black-forest-labs/FLUX.1-pro":
862
  siliconflow_data["width"] = data.get("width", 1024)
863
  siliconflow_data["height"] = data.get("height", 768)
 
953
  image_url = images[0]
954
  logging.info(f"Extracted image URL: {image_url}")
955
 
956
+ markdown_image_link = create_base64_markdown_image(image_url)
957
  if image_url:
958
  chunk_data = {
959
  "id": f"chatcmpl-{uuid.uuid4()}",