Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -97,32 +97,24 @@ def generate_image(prompt):
|
|
| 97 |
if not prompt.strip(): return None, 'Please enter a description.'
|
| 98 |
if not HF_TOKEN: return None, 'Error: Add HF_TOKEN to Space Settings Secrets.'
|
| 99 |
try:
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
'https://
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
headers=headers, json=payload, timeout=60
|
| 117 |
-
)
|
| 118 |
-
if r2.status_code == 200:
|
| 119 |
-
img = Image.open(io.BytesIO(r2.content))
|
| 120 |
-
return img, 'Image generated!'
|
| 121 |
-
return None, 'Model loading, please wait 30 seconds and try again.'
|
| 122 |
-
else:
|
| 123 |
-
return None, 'Error: '+str(r.status_code)+' '+r.text[:200]
|
| 124 |
except Exception as e:
|
| 125 |
-
return None, 'Error: '+str(e)
|
| 126 |
|
| 127 |
def piv_tool(velocity, shear, hr):
|
| 128 |
v = 'HIGH - stenosis risk' if float(velocity)>2.0 else 'NORMAL'
|
|
|
|
| 97 |
if not prompt.strip(): return None, 'Please enter a description.'
|
| 98 |
if not HF_TOKEN: return None, 'Error: Add HF_TOKEN to Space Settings Secrets.'
|
| 99 |
try:
|
| 100 |
+
full_prompt = 'Highly detailed scientific biomedical illustration of: ' + prompt + ', professional medical diagram, high quality, detailed'
|
| 101 |
+
headers = {'Authorization': 'Bearer ' + HF_TOKEN, 'Content-Type': 'application/json'}
|
| 102 |
+
payload = {'inputs': full_prompt, 'parameters': {'num_inference_steps': 4}}
|
| 103 |
+
models = [
|
| 104 |
+
'https://router.huggingface.co/hf-inference/models/black-forest-labs/FLUX.1-schnell',
|
| 105 |
+
'https://router.huggingface.co/hf-inference/models/stabilityai/stable-diffusion-xl-base-1.0',
|
| 106 |
+
'https://router.huggingface.co/hf-inference/models/runwayml/stable-diffusion-v1-5',
|
| 107 |
+
]
|
| 108 |
+
for model_url in models:
|
| 109 |
+
try:
|
| 110 |
+
r = requests.post(model_url, headers=headers, json=payload, timeout=60)
|
| 111 |
+
if r.status_code == 200:
|
| 112 |
+
img = Image.open(io.BytesIO(r.content))
|
| 113 |
+
return img, 'Image generated!'
|
| 114 |
+
except: continue
|
| 115 |
+
return None, 'All models busy. Please wait 30 seconds and try again.'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
except Exception as e:
|
| 117 |
+
return None, 'Error: ' + str(e)
|
| 118 |
|
| 119 |
def piv_tool(velocity, shear, hr):
|
| 120 |
v = 'HIGH - stenosis risk' if float(velocity)>2.0 else 'NORMAL'
|