Spaces:
Build error
Build error
Update main.py
Browse files
main.py
CHANGED
|
@@ -15,6 +15,8 @@ import aiohttp
|
|
| 15 |
import asyncio
|
| 16 |
import json
|
| 17 |
from types import SimpleNamespace
|
|
|
|
|
|
|
| 18 |
|
| 19 |
#--------------------------------------------------- Definizione Server FAST API ------------------------------------------------------
|
| 20 |
app = FastAPI()
|
|
@@ -500,6 +502,27 @@ def generate_image(request: Request, input_data: InputImage):
|
|
| 500 |
return {"error": "Errore interno del server persistente!"}
|
| 501 |
return {"error": "Numero massimo di tentativi raggiunto"}
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
|
| 504 |
#--------------------------------------------------- API PostSpazio ------------------------------------------------------
|
| 505 |
@app.post("/PostSpazio")
|
|
|
|
| 15 |
import asyncio
|
| 16 |
import json
|
| 17 |
from types import SimpleNamespace
|
| 18 |
+
from io import BytesIO
|
| 19 |
+
from PIL import Image
|
| 20 |
|
| 21 |
#--------------------------------------------------- Definizione Server FAST API ------------------------------------------------------
|
| 22 |
app = FastAPI()
|
|
|
|
| 502 |
return {"error": "Errore interno del server persistente!"}
|
| 503 |
return {"error": "Numero massimo di tentativi raggiunto"}
|
| 504 |
|
| 505 |
+
#--------------------------------------------------- IMAGE TO TEXT ------------------------------------------------------
|
| 506 |
+
class InputImageToText(BaseModel):
|
| 507 |
+
base64: str
|
| 508 |
+
input: str = ''
|
| 509 |
+
|
| 510 |
+
def base64_in_immagine(dati_base64):
|
| 511 |
+
immagine = base64.b64decode(dati_base64)
|
| 512 |
+
immagine_pil = Image.open(BytesIO(immagine))
|
| 513 |
+
nome_file = "img.jpg"
|
| 514 |
+
immagine_pil.save(nome_file)
|
| 515 |
+
|
| 516 |
+
@app.post("/Image_To_Text")
|
| 517 |
+
def image_to_text(request: Request, input_data: InputImageToText):
|
| 518 |
+
base64_in_immagine(InputImageToText.base64)
|
| 519 |
+
client = Client("vikhyatk/moondream2")
|
| 520 |
+
result = client.predict(
|
| 521 |
+
"img.jpg",
|
| 522 |
+
"Describe Image",
|
| 523 |
+
api_name="/answer_question_1"
|
| 524 |
+
)
|
| 525 |
+
return {"response": result}
|
| 526 |
|
| 527 |
#--------------------------------------------------- API PostSpazio ------------------------------------------------------
|
| 528 |
@app.post("/PostSpazio")
|