Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,42 +5,14 @@ import time
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
-
|
| 9 |
-
url = "https://fluxaiweb.com/flux/getToken"
|
| 10 |
-
response = requests.get(url)
|
| 11 |
-
if response.status_code == 200:
|
| 12 |
-
response_json = response.json()
|
| 13 |
-
return response_json.get("data", {}).get("token")
|
| 14 |
-
return None
|
| 15 |
-
|
| 16 |
-
def req_flux(token, prompt_value, aspect_ratio="1:1", output_format="webp", num_outputs=1, output_quality=90):
|
| 17 |
-
url = "https://fluxaiweb.com/flux/generateImage"
|
| 18 |
-
payload = {
|
| 19 |
-
"prompt": prompt_value,
|
| 20 |
-
"aspectRatio": aspect_ratio,
|
| 21 |
-
"outputFormat": output_format,
|
| 22 |
-
"numOutputs": num_outputs,
|
| 23 |
-
"outputQuality": output_quality
|
| 24 |
-
}
|
| 25 |
-
headers = {
|
| 26 |
-
'Content-Type': 'application/json',
|
| 27 |
-
'token': token
|
| 28 |
-
}
|
| 29 |
-
try:
|
| 30 |
-
response = requests.post(url, headers=headers, json=payload)
|
| 31 |
-
response.raise_for_status()
|
| 32 |
-
data = response.json()
|
| 33 |
-
return data.get("data", {}).get("image")
|
| 34 |
-
except requests.exceptions.RequestException as e:
|
| 35 |
-
print(f"Error making request: {e}")
|
| 36 |
-
return None
|
| 37 |
|
| 38 |
def generate_fake_stream(image_url):
|
| 39 |
chunks = [
|
| 40 |
"I'm generating an image based on your prompt...",
|
| 41 |
"The image is being processed...",
|
| 42 |
"Almost there...",
|
| 43 |
-
f"Image generated successfully!
|
| 44 |
]
|
| 45 |
|
| 46 |
for i, chunk in enumerate(chunks):
|
|
@@ -82,7 +54,7 @@ def chat_completions():
|
|
| 82 |
"index": 0,
|
| 83 |
"message": {
|
| 84 |
"role": "assistant",
|
| 85 |
-
"content": f"I've generated an image based on your prompt.
|
| 86 |
},
|
| 87 |
"finish_reason": "stop"
|
| 88 |
}
|
|
|
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
|
| 8 |
+
# get_token 和 req_flux 函数保持不变
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def generate_fake_stream(image_url):
|
| 11 |
chunks = [
|
| 12 |
"I'm generating an image based on your prompt...",
|
| 13 |
"The image is being processed...",
|
| 14 |
"Almost there...",
|
| 15 |
+
f"Image generated successfully! Here it is:\n\n"
|
| 16 |
]
|
| 17 |
|
| 18 |
for i, chunk in enumerate(chunks):
|
|
|
|
| 54 |
"index": 0,
|
| 55 |
"message": {
|
| 56 |
"role": "assistant",
|
| 57 |
+
"content": f"I've generated an image based on your prompt. Here it is:\n\n"
|
| 58 |
},
|
| 59 |
"finish_reason": "stop"
|
| 60 |
}
|