kopia lustrzana https://github.com/sepandhaghighi/samila
Timeout (#182)
* fix : nft_storage_upload function updated * doc : CHANGELOG updated * fix : autopep8 * doc : README updated * doc : minor edit in notebook flags * fix : minor edit in stylepull/180/head
rodzic
a54a5107a5
commit
be973ee183
|
@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||
- `rotate` function
|
||||
### Changed
|
||||
- `rotation` parameter added to `plot` method
|
||||
- `timeout` parameter added to `nft_storage` method
|
||||
- `load_config` function modified
|
||||
- `nft_storage_upload` function modified
|
||||
- Random mode modified
|
||||
- `RANDOM_EQUATION_GEN_COMPLEXITY` parameter renamed to `RANDOM_EQUATION_MAX_COMPLEXITY`
|
||||
- `README.md` updated
|
||||
|
|
|
@ -179,7 +179,7 @@ You can even rotate your art by using `rotation` parameter. Enter your desired r
|
|||
>>> g.plot(rotation=45)
|
||||
```
|
||||
|
||||
* Default rotation is 0.
|
||||
* Default rotation is 0
|
||||
|
||||
### Range
|
||||
```pycon
|
||||
|
@ -253,7 +253,7 @@ You can make your custom color map and use it in Samila
|
|||
Upload generated image directly to [NFT.storage](https://NFT.storage)
|
||||
|
||||
```pycon
|
||||
>>> g.nft_storage(api_key="YOUR_API_KEY")
|
||||
>>> g.nft_storage(api_key="YOUR_API_KEY", timeout=5000)
|
||||
{'status': True, 'message': 'FILE_LINK'}
|
||||
```
|
||||
|
||||
|
@ -268,6 +268,8 @@ or
|
|||
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
|
||||
```
|
||||
|
||||
* Default timeout is **3000** seconds
|
||||
|
||||
### Save image
|
||||
Save generated image
|
||||
|
||||
|
|
|
@ -134,7 +134,6 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
|
@ -412,6 +411,15 @@
|
|||
"g1.nft_storage(api_key=\"YOUR_API_KEY\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"g1.nft_storage(api_key=\"YOUR_API_KEY\", timeout=5000)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -436,11 +444,18 @@
|
|||
"source": [
|
||||
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_data=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"* Default timeout is **3000** seconds"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.8.10 64-bit",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
@ -454,7 +469,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
"version": "3.5.2"
|
||||
},
|
||||
"toc": {
|
||||
"base_numbering": 1,
|
||||
|
|
|
@ -499,7 +499,7 @@ def _GI_initializer(g, function1, function2):
|
|||
g.missed_points_number = 0
|
||||
|
||||
|
||||
def nft_storage_upload(api_key, data):
|
||||
def nft_storage_upload(api_key, data, timeout):
|
||||
"""
|
||||
Upload file to nft.storage.
|
||||
|
||||
|
@ -507,6 +507,8 @@ def nft_storage_upload(api_key, data):
|
|||
:type api_key: str
|
||||
:param data: image data
|
||||
:type data: binary
|
||||
:param timeout: upload timeout (in seconds)
|
||||
:type timeout: int
|
||||
:return: result as dict
|
||||
"""
|
||||
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
|
||||
|
@ -515,7 +517,8 @@ def nft_storage_upload(api_key, data):
|
|||
response = requests.post(
|
||||
url=NFT_STORAGE_API,
|
||||
data=data,
|
||||
headers=headers)
|
||||
headers=headers,
|
||||
timeout=timeout)
|
||||
response_json = response.json()
|
||||
if response_json["ok"]:
|
||||
result["message"] = NFT_STORAGE_LINK.format(
|
||||
|
|
|
@ -172,7 +172,8 @@ class GenerativeImage:
|
|||
api_key,
|
||||
upload_data=False,
|
||||
upload_config=False,
|
||||
depth=None):
|
||||
depth=None,
|
||||
timeout=3000):
|
||||
"""
|
||||
Upload image to nft.storage.
|
||||
|
||||
|
@ -184,6 +185,8 @@ class GenerativeImage:
|
|||
:type upload_config: bool
|
||||
:param depth: image depth
|
||||
:type depth: float
|
||||
:param timeout: upload timeout (in seconds)
|
||||
:type timeout: int
|
||||
:return: result as dict
|
||||
"""
|
||||
save_params_filter(self, depth)
|
||||
|
@ -191,20 +194,25 @@ class GenerativeImage:
|
|||
if not response["status"]:
|
||||
return {"status": False, "message": response["message"]}
|
||||
buf = response["buffer"]
|
||||
response = nft_storage_upload(api_key=api_key, data=buf.getvalue())
|
||||
response = nft_storage_upload(
|
||||
api_key=api_key,
|
||||
data=buf.getvalue(),
|
||||
timeout=timeout)
|
||||
if upload_config == False and upload_data == False:
|
||||
return response
|
||||
result = {key: {'image': value} for key, value in response.items()}
|
||||
if upload_config:
|
||||
response = nft_storage_upload(
|
||||
api_key=api_key,
|
||||
data=json.dumps(get_config(self)))
|
||||
data=json.dumps(get_config(self)),
|
||||
timeout=timeout)
|
||||
for key, value in response.items():
|
||||
result[key]['config'] = value
|
||||
if upload_data:
|
||||
response = nft_storage_upload(
|
||||
api_key=api_key,
|
||||
data=json.dumps(get_data(self)))
|
||||
data=json.dumps(get_data(self)),
|
||||
timeout=timeout)
|
||||
for key, value in response.items():
|
||||
result[key]['data'] = value
|
||||
return result
|
||||
|
|
Ładowanie…
Reference in New Issue