Spaces:
Sleeping
Sleeping
Commit
·
29bc3a1
1
Parent(s):
b8446db
Update main.py
Browse files
main.py
CHANGED
|
@@ -3,6 +3,8 @@ 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 |
|
| 7 |
app = FastAPI()
|
| 8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
@@ -49,6 +51,31 @@ def read_root(request: Request, input_data: InputData):
|
|
| 49 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 50 |
return {"response": generated_response}
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
@app.get("/")
|
| 53 |
def read_general():
|
| 54 |
return {"response": "Benvenuto. Per maggiori info vai a /docs"} # Restituisci la risposta generata come JSON
|
|
|
|
| 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")
|
|
|
|
| 51 |
generated_response = generate(input_text, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
| 52 |
return {"response": generated_response}
|
| 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 ",
|
| 60 |
+
"",
|
| 61 |
+
25,
|
| 62 |
+
5,
|
| 63 |
+
1024,
|
| 64 |
+
1024,
|
| 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():
|
| 81 |
return {"response": "Benvenuto. Per maggiori info vai a /docs"} # Restituisci la risposta generata come JSON
|