Spaces:
Sleeping
Sleeping
Commit
·
5f6ac1e
1
Parent(s):
29bc3a1
Update main.py
Browse files
main.py
CHANGED
|
@@ -3,8 +3,6 @@ from fastapi.middleware.cors import CORSMiddleware # Importa il middleware CORS
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
from datetime import datetime
|
| 6 |
-
from fastapi.responses import JSONResponse
|
| 7 |
-
import base64
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
@@ -53,7 +51,6 @@ def read_root(request: Request, input_data: InputData):
|
|
| 53 |
|
| 54 |
@app.get("/Immagine")
|
| 55 |
def generate_image():
|
| 56 |
-
# Chiamata al servizio gradio_client per ottenere l'immagine
|
| 57 |
client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
|
| 58 |
result = client.predict(
|
| 59 |
"a giant monster hybrid of dragon and spider, in dark dense foggy forest ",
|
|
@@ -65,16 +62,7 @@ def generate_image():
|
|
| 65 |
453666937,
|
| 66 |
fn_index=0
|
| 67 |
)
|
| 68 |
-
|
| 69 |
-
# Assume che 'result' sia l'immagine restituita come BASE64
|
| 70 |
-
image_base64 = result.get("data") # Assumi che 'data' contenga l'immagine come BASE64
|
| 71 |
-
|
| 72 |
-
if image_base64:
|
| 73 |
-
# Ritorna la risposta come JSON contenente il BASE64 dell'immagine
|
| 74 |
-
return JSONResponse(content={"image_base64": image_base64})
|
| 75 |
-
else:
|
| 76 |
-
# Nel caso in cui non si riesca a ottenere l'immagine
|
| 77 |
-
return JSONResponse(content={"message": "Impossibile ottenere l'immagine"}, status_code=500)
|
| 78 |
|
| 79 |
@app.get("/")
|
| 80 |
def read_general():
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
from datetime import datetime
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
|
|
| 51 |
|
| 52 |
@app.get("/Immagine")
|
| 53 |
def generate_image():
|
|
|
|
| 54 |
client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
|
| 55 |
result = client.predict(
|
| 56 |
"a giant monster hybrid of dragon and spider, in dark dense foggy forest ",
|
|
|
|
| 62 |
453666937,
|
| 63 |
fn_index=0
|
| 64 |
)
|
| 65 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
@app.get("/")
|
| 68 |
def read_general():
|