prlabs2023 commited on
Commit
b343fc6
·
1 Parent(s): 8e27bee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -23,6 +23,7 @@ from typing import Annotated
23
  from transformers import BertTokenizerFast, EncoderDecoderModel
24
  import torch
25
  import random
 
26
  import string
27
  import time
28
  from huggingface_hub import InferenceClient
@@ -178,5 +179,25 @@ def do_ML(filename:str,text:str,code:str,host:str):
178
  data={"text":text,"filename":filename}
179
  requests.post(host+"texttoimage2handleerror",data=data)
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
 
 
23
  from transformers import BertTokenizerFast, EncoderDecoderModel
24
  import torch
25
  import random
26
+ from fastapi import FastAPI, Response
27
  import string
28
  import time
29
  from huggingface_hub import InferenceClient
 
179
  data={"text":text,"filename":filename}
180
  requests.post(host+"texttoimage2handleerror",data=data)
181
 
182
+ @app.post("/image")
183
+ async def get_answer(q: Query ):
184
+ text = q.text
185
+ try:
186
+ global client
187
+ imagei = client.text_to_image(text)
188
+ byte_array = io.BytesIO()
189
+ imagei.save(byte_array, format='JPEG')
190
+ response = Response(content=byte_array.getvalue(), media_type="image/png")
191
+ return response
192
+
193
+ except:
194
+ return JSONResponse({"status":False})
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
 
203