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
|
- `rotate` function
|
||||||
### Changed
|
### Changed
|
||||||
- `rotation` parameter added to `plot` method
|
- `rotation` parameter added to `plot` method
|
||||||
|
- `timeout` parameter added to `nft_storage` method
|
||||||
- `load_config` function modified
|
- `load_config` function modified
|
||||||
|
- `nft_storage_upload` function modified
|
||||||
- Random mode modified
|
- Random mode modified
|
||||||
- `RANDOM_EQUATION_GEN_COMPLEXITY` parameter renamed to `RANDOM_EQUATION_MAX_COMPLEXITY`
|
- `RANDOM_EQUATION_GEN_COMPLEXITY` parameter renamed to `RANDOM_EQUATION_MAX_COMPLEXITY`
|
||||||
- `README.md` updated
|
- `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)
|
>>> g.plot(rotation=45)
|
||||||
```
|
```
|
||||||
|
|
||||||
* Default rotation is 0.
|
* Default rotation is 0
|
||||||
|
|
||||||
### Range
|
### Range
|
||||||
```pycon
|
```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)
|
Upload generated image directly to [NFT.storage](https://NFT.storage)
|
||||||
|
|
||||||
```pycon
|
```pycon
|
||||||
>>> g.nft_storage(api_key="YOUR_API_KEY")
|
>>> g.nft_storage(api_key="YOUR_API_KEY", timeout=5000)
|
||||||
{'status': True, 'message': 'FILE_LINK'}
|
{'status': True, 'message': 'FILE_LINK'}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -268,6 +268,8 @@ or
|
||||||
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
|
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Default timeout is **3000** seconds
|
||||||
|
|
||||||
### Save image
|
### Save image
|
||||||
Save generated image
|
Save generated image
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,6 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"attachments": {},
|
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -412,6 +411,15 @@
|
||||||
"g1.nft_storage(api_key=\"YOUR_API_KEY\")"
|
"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",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
|
@ -436,11 +444,18 @@
|
||||||
"source": [
|
"source": [
|
||||||
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_data=True)"
|
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_data=True)"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"* Default timeout is **3000** seconds"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3.8.10 64-bit",
|
"display_name": "Python 3",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
"name": "python3"
|
"name": "python3"
|
||||||
},
|
},
|
||||||
|
@ -454,7 +469,7 @@
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.8.10"
|
"version": "3.5.2"
|
||||||
},
|
},
|
||||||
"toc": {
|
"toc": {
|
||||||
"base_numbering": 1,
|
"base_numbering": 1,
|
||||||
|
|
|
@ -499,7 +499,7 @@ def _GI_initializer(g, function1, function2):
|
||||||
g.missed_points_number = 0
|
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.
|
Upload file to nft.storage.
|
||||||
|
|
||||||
|
@ -507,6 +507,8 @@ def nft_storage_upload(api_key, data):
|
||||||
:type api_key: str
|
:type api_key: str
|
||||||
:param data: image data
|
:param data: image data
|
||||||
:type data: binary
|
:type data: binary
|
||||||
|
:param timeout: upload timeout (in seconds)
|
||||||
|
:type timeout: int
|
||||||
:return: result as dict
|
:return: result as dict
|
||||||
"""
|
"""
|
||||||
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
|
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
|
||||||
|
@ -515,7 +517,8 @@ def nft_storage_upload(api_key, data):
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url=NFT_STORAGE_API,
|
url=NFT_STORAGE_API,
|
||||||
data=data,
|
data=data,
|
||||||
headers=headers)
|
headers=headers,
|
||||||
|
timeout=timeout)
|
||||||
response_json = response.json()
|
response_json = response.json()
|
||||||
if response_json["ok"]:
|
if response_json["ok"]:
|
||||||
result["message"] = NFT_STORAGE_LINK.format(
|
result["message"] = NFT_STORAGE_LINK.format(
|
||||||
|
|
|
@ -172,7 +172,8 @@ class GenerativeImage:
|
||||||
api_key,
|
api_key,
|
||||||
upload_data=False,
|
upload_data=False,
|
||||||
upload_config=False,
|
upload_config=False,
|
||||||
depth=None):
|
depth=None,
|
||||||
|
timeout=3000):
|
||||||
"""
|
"""
|
||||||
Upload image to nft.storage.
|
Upload image to nft.storage.
|
||||||
|
|
||||||
|
@ -184,6 +185,8 @@ class GenerativeImage:
|
||||||
:type upload_config: bool
|
:type upload_config: bool
|
||||||
:param depth: image depth
|
:param depth: image depth
|
||||||
:type depth: float
|
:type depth: float
|
||||||
|
:param timeout: upload timeout (in seconds)
|
||||||
|
:type timeout: int
|
||||||
:return: result as dict
|
:return: result as dict
|
||||||
"""
|
"""
|
||||||
save_params_filter(self, depth)
|
save_params_filter(self, depth)
|
||||||
|
@ -191,20 +194,25 @@ class GenerativeImage:
|
||||||
if not response["status"]:
|
if not response["status"]:
|
||||||
return {"status": False, "message": response["message"]}
|
return {"status": False, "message": response["message"]}
|
||||||
buf = response["buffer"]
|
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:
|
if upload_config == False and upload_data == False:
|
||||||
return response
|
return response
|
||||||
result = {key: {'image': value} for key, value in response.items()}
|
result = {key: {'image': value} for key, value in response.items()}
|
||||||
if upload_config:
|
if upload_config:
|
||||||
response = nft_storage_upload(
|
response = nft_storage_upload(
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
data=json.dumps(get_config(self)))
|
data=json.dumps(get_config(self)),
|
||||||
|
timeout=timeout)
|
||||||
for key, value in response.items():
|
for key, value in response.items():
|
||||||
result[key]['config'] = value
|
result[key]['config'] = value
|
||||||
if upload_data:
|
if upload_data:
|
||||||
response = nft_storage_upload(
|
response = nft_storage_upload(
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
data=json.dumps(get_data(self)))
|
data=json.dumps(get_data(self)),
|
||||||
|
timeout=timeout)
|
||||||
for key, value in response.items():
|
for key, value in response.items():
|
||||||
result[key]['data'] = value
|
result[key]['data'] = value
|
||||||
return result
|
return result
|
||||||
|
|
Ładowanie…
Reference in New Issue