MatteoScript commited on
Commit
31c3ad2
·
1 Parent(s): 1290a3c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -11
main.py CHANGED
@@ -33,8 +33,8 @@ class InputImage(BaseModel):
33
  input: str
34
  negativePrompt: str = ''
35
  steps: int = 25
36
- cfg: int = 5
37
- seed: int = 453666937
38
 
39
  #--------------------------------------------------- Generazione TESTO ------------------------------------------------------
40
  @app.post("/Genera")
@@ -78,7 +78,7 @@ def format_prompt(message, history):
78
  @app.post("/Immagine")
79
  def generate_image(request: Request, input_data: InputImage):
80
  client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
81
- max_attempts = 10
82
  attempt = 0
83
  while attempt < max_attempts:
84
  try:
@@ -98,15 +98,12 @@ def generate_image(request: Request, input_data: InputImage):
98
  img_base64 = base64.b64encode(img_binary).decode('utf-8')
99
  return {"response": img_base64}
100
  except requests.exceptions.HTTPError as e:
101
- if e.response.status_code == 500:
102
- time.sleep(1)
103
- attempt += 1
104
- if attempt < max_attempts:
105
- continue
106
- else:
107
- return {"error": "Errore interno del server persistente"}
108
  else:
109
- return {"error": "Errore diverso da 500"}
110
  return {"error": "Numero massimo di tentativi raggiunto"}
111
 
112
  @app.get("/")
 
33
  input: str
34
  negativePrompt: str = ''
35
  steps: int = 25
36
+ cfg: int = 7
37
+ seed: int = -1
38
 
39
  #--------------------------------------------------- Generazione TESTO ------------------------------------------------------
40
  @app.post("/Genera")
 
78
  @app.post("/Immagine")
79
  def generate_image(request: Request, input_data: InputImage):
80
  client = Client("https://openskyml-fast-sdxl-stable-diffusion-xl.hf.space/--replicas/545b5tw7n/")
81
+ max_attempts = 20
82
  attempt = 0
83
  while attempt < max_attempts:
84
  try:
 
98
  img_base64 = base64.b64encode(img_binary).decode('utf-8')
99
  return {"response": img_base64}
100
  except requests.exceptions.HTTPError as e:
101
+ time.sleep(1)
102
+ attempt += 1
103
+ if attempt < max_attempts:
104
+ continue
 
 
 
105
  else:
106
+ return {"error": "Errore interno del server persistente"}
107
  return {"error": "Numero massimo di tentativi raggiunto"}
108
 
109
  @app.get("/")