Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,6 +31,7 @@ def respond(message, history):
|
|
| 31 |
#prompt = list(itertools.chain.from_iterable(history))
|
| 32 |
#prompt.append(message)
|
| 33 |
|
|
|
|
| 34 |
prompt = pd.DataFrame(
|
| 35 |
{"prompt": [message], "num_inference_steps": 25}
|
| 36 |
)
|
|
@@ -41,31 +42,40 @@ def respond(message, history):
|
|
| 41 |
|
| 42 |
embed_image_markdown = ""
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return embed_image_markdown
|
| 70 |
|
| 71 |
|
|
|
|
| 31 |
#prompt = list(itertools.chain.from_iterable(history))
|
| 32 |
#prompt.append(message)
|
| 33 |
|
| 34 |
+
# プロンプトの作成
|
| 35 |
prompt = pd.DataFrame(
|
| 36 |
{"prompt": [message], "num_inference_steps": 25}
|
| 37 |
)
|
|
|
|
| 42 |
|
| 43 |
embed_image_markdown = ""
|
| 44 |
|
| 45 |
+
try:
|
| 46 |
+
# モデルサービングエンドポイントに問い合わせ
|
| 47 |
+
response = requests.request(method="POST", headers=headers, url=local_endpoint, data=data_json)
|
| 48 |
+
response_data = response.json()
|
| 49 |
+
#print(response_data["predictions"])
|
| 50 |
+
|
| 51 |
+
# numpy arrayに変換
|
| 52 |
+
im_array = np.array(response_data["predictions"], dtype=np.uint8)
|
| 53 |
+
#print(im_array)
|
| 54 |
+
# 画像に変換
|
| 55 |
+
im = Image.fromarray(im_array, 'RGB')
|
| 56 |
|
| 57 |
|
| 58 |
+
# debug
|
| 59 |
+
#image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg"
|
| 60 |
+
#print("image_url:", image_url)
|
| 61 |
+
#im = Image.open(io.BytesIO(requests.get(image_url).content))
|
| 62 |
+
#numpydata = np.asarray(im)
|
| 63 |
+
|
| 64 |
+
rawBytes = io.BytesIO()
|
| 65 |
+
im.save(rawBytes, "PNG")
|
| 66 |
+
rawBytes.seek(0) # ファイルの先頭に移動
|
| 67 |
+
# base64にエンコード
|
| 68 |
+
image_encoded = base64.b64encode(rawBytes.read()).decode('ascii')
|
| 69 |
+
#print(image_encoded)
|
| 70 |
+
|
| 71 |
+
# マークダウンに埋め込み
|
| 72 |
+
embed_image_markdown = f""
|
| 73 |
+
#print(embed_image_markdown)
|
| 74 |
+
|
| 75 |
+
except Exception as error:
|
| 76 |
+
response_data = f"ERROR status_code: {type(error).__name__}"
|
| 77 |
+
#+ str(response.status_code) + " response:" + response.text
|
| 78 |
+
|
| 79 |
return embed_image_markdown
|
| 80 |
|
| 81 |
|