-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16876ff
commit 57d5871
Showing
22 changed files
with
346 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Filename: __init__.py | ||
Author: Iliya Vereshchagin | ||
Copyright (c) 2023. All rights reserved. | ||
Created: 16.10.2023 | ||
Last Modified: 17.10.2023 | ||
Description: | ||
This file is init file for examples package. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Filename: __init__.py | ||
Author: Iliya Vereshchagin | ||
Copyright (c) 2023. All rights reserved. | ||
Created: 16.10.2023 | ||
Last Modified: 17.10.2023 | ||
Description: | ||
This file is init file for image_generation package. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Filename: dalle_test.py | ||
Author: Iliya Vereshchagin | ||
Copyright (c) 2023. All rights reserved. | ||
Created: 15.10.2023 | ||
Last Modified: 17.10.2023 | ||
Description: | ||
This file contains testing procedures for DALLE experiments | ||
""" | ||
import asyncio | ||
|
||
from examples.creds import oai_token, oai_organization | ||
from openai_api.src.openai_api import DALLE | ||
from creds import oai_token, oai_organization | ||
|
||
from time import sleep | ||
|
||
dalle = DALLE(auth_token=oai_token, organization=oai_organization) | ||
|
||
|
||
async def main(): | ||
resp = await dalle.create_image_url('robocop (robot policeman, from 80s movie)') | ||
"""Main function for testing DALLE.""" | ||
resp = await dalle.create_image_url("robocop (robot policeman, from 80s movie)") | ||
print(resp) | ||
resp = await dalle.create_variation_from_url(resp[0]) | ||
print(resp) | ||
|
||
asyncio.run(main()) | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,131 @@ | ||
import requests | ||
from PIL import Image | ||
from io import BytesIO | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Filename: gpt_functions.py | ||
Author: Iliya Vereshchagin | ||
Copyright (c) 2023. All rights reserved. | ||
Created: 15.10.2023 | ||
Last Modified: 17.10.2023 | ||
Description: | ||
This file contains testing functions for ChatGPT function calling using DALLE and Leonardo experiments | ||
""" | ||
import json | ||
from io import BytesIO | ||
|
||
from creds import oai_token, oai_organization | ||
import requests | ||
from PIL import Image | ||
|
||
from examples.creds import oai_token, oai_organization | ||
from leonardo_api.src.leonardo_api.leonardo_sync import Leonardo | ||
from openai_api.src.openai_api.dalle import DALLE | ||
from leonardo_api.leonardo_sync import Leonardo | ||
from page_retriever import PageRetriever | ||
from pytest_runner import run_tests | ||
|
||
|
||
doc_engine = PageRetriever('https://wwakabobik.github.io/') | ||
def get_weather(city, units): | ||
""" | ||
Get the weather for a given city. | ||
:param city: The city to get the weather for. | ||
:param units: The units to use for the weather. | ||
def get_weather(city, units): | ||
:return: The weather for the given city. | ||
""" | ||
base_url = "http://api.openweathermap.org/data/2.5/weather" | ||
params = { | ||
"q": city, | ||
"appid": "93171b03384f92ee3c55873452a49c7c", | ||
"units": units | ||
} | ||
params = {"q": city, "appid": "93171b03384f92ee3c55873452a49c7c", "units": units} | ||
response = requests.get(base_url, params=params) | ||
data = response.json() | ||
return data | ||
|
||
|
||
def get_current_weather(location, unit="metric"): | ||
"""Get the current weather in a given location""" | ||
""" | ||
Get the current weather in a given location | ||
:param location: (str) The location to get the weather for. | ||
:param unit: (str) The unit to use for the weather. | ||
""" | ||
owm_info = get_weather(location, units=unit) | ||
weather_info = { | ||
"location": location, | ||
"temperature": owm_info["main"]["temp"], | ||
"unit": unit, | ||
"forecast": owm_info["weather"][0]["description"], | ||
"wind": owm_info["wind"]["speed"] | ||
"wind": owm_info["wind"]["speed"], | ||
} | ||
return json.dumps(weather_info) | ||
|
||
|
||
def draw_image_using_dalle(prompt): | ||
""" | ||
Draws image using user prompt. Returns url of image. | ||
:param prompt: (str) Prompt, the description, what should be drawn and how | ||
:return: (str) url of image | ||
""" | ||
dalle = DALLE(auth_token=oai_token, organization=oai_organization) | ||
image = dalle.create_image_url(prompt) | ||
url_dict = {'image_url': image[0]} | ||
url_dict = {"image_url": image[0]} | ||
response = requests.get(image[0]) | ||
img = Image.open(BytesIO(response.content)) | ||
img.show() | ||
return json.dumps(url_dict) | ||
|
||
|
||
def draw_image(prompt): | ||
leonardo = Leonardo(auth_token='a0178171-c67f-4922-afb3-458f24ecef1a') | ||
""" | ||
Draws image using user prompt. Returns url of image. | ||
:param prompt: (str) Prompt, the description, what should be drawn and how | ||
:return: (dict) dict with url of image | ||
""" | ||
leonardo = Leonardo(auth_token="a0178171-c67f-4922-afb3-458f24ecef1a") | ||
leonardo.get_user_info() | ||
response = leonardo.post_generations(prompt=prompt, num_images=1, guidance_scale=5, | ||
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768) | ||
response = leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId']) | ||
url_dict = {'image_url': response[0]['url']} | ||
response = requests.get(url_dict['image_url']) | ||
response = leonardo.post_generations( | ||
prompt=prompt, | ||
num_images=1, | ||
guidance_scale=5, | ||
model_id="e316348f-7773-490e-adcd-46757c738eb7", | ||
width=1024, | ||
height=768, | ||
) | ||
response = leonardo.wait_for_image_generation(generation_id=response["sdGenerationJob"]["generationId"]) | ||
url_dict = {"image_url": response[0]["url"]} | ||
response = requests.get(url_dict["image_url"]) | ||
img = Image.open(BytesIO(response.content)) | ||
img.show() | ||
return json.dumps(url_dict) | ||
|
||
|
||
gpt_functions = [ | ||
{ | ||
"name": "draw_image", | ||
"description": "Draws image using user prompt. Returns url of image.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"prompt": { | ||
"type": "string", | ||
"description": "Prompt, the description, what should be drawn and how", | ||
}, | ||
{ | ||
"name": "draw_image", | ||
"description": "Draws image using user prompt. Returns url of image.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"prompt": { | ||
"type": "string", | ||
"description": "Prompt, the description, what should be drawn and how", | ||
}, | ||
"required": ["prompt"], | ||
}, | ||
"required": ["prompt"], | ||
}, | ||
{ | ||
"name": "get_current_weather", | ||
"description": "Get the current weather in a given location", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"location": { | ||
"type": "string", | ||
"description": "The city and state, e.g. San Francisco, CA", | ||
}, | ||
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, | ||
}, | ||
{ | ||
"name": "get_current_weather", | ||
"description": "Get the current weather in a given location", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"location": { | ||
"type": "string", | ||
"description": "The city and state, e.g. San Francisco, CA", | ||
}, | ||
"required": ["location"], | ||
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, | ||
}, | ||
"required": ["location"], | ||
}, | ||
{ | ||
"name": "get_page_code", | ||
"description": "Get page code to generate locators and tests", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"url": { | ||
"type": "string", | ||
"description": "The URL of the page to get the code from" | ||
} | ||
}, | ||
"required": [] | ||
} | ||
}, | ||
{ | ||
"name": "get_tests_results", | ||
"description": "Get the results of the tests", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"test_files": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "The list of test files to run" | ||
} | ||
}, | ||
"required": [] | ||
} | ||
} | ||
] | ||
|
||
gpt_functions_dict = {'get_current_weather': get_current_weather, | ||
'draw_image': draw_image, | ||
'get_page_code': doc_engine.get_body_without_scripts, | ||
'get_tests_results': run_tests('tests/test_example.py')} | ||
}, | ||
] | ||
|
||
gpt_functions_dict = {"get_current_weather": get_current_weather, "draw_image": draw_image} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import json | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Filename: test_leonardo.py | ||
Author: Iliya Vereshchagin | ||
Copyright (c) 2023. All rights reserved. | ||
Created: 15.10.2023 | ||
Last Modified: 17.10.2023 | ||
Description: | ||
This file contains testing procedures for Leonardo experiments | ||
""" | ||
import asyncio | ||
import json | ||
|
||
from leonardo_api import LeonardoAsync as Leonardo | ||
|
||
|
||
async def main(): | ||
leonardo = Leonardo(auth_token='a0178171-c67f-4922-afb3-458f24ecef1a') | ||
"""Main function""" | ||
leonardo = Leonardo(auth_token="a0178171-c67f-4922-afb3-458f24ecef1a") | ||
response = await leonardo.get_user_info() | ||
print(response) | ||
response = await leonardo.post_generations(prompt="a beautiful necromancer witch resurrects skeletons against " | ||
"the backdrop of a burning ruined castle", num_images=1, | ||
negative_prompt='bright colors, good characters, positive', | ||
model_id='e316348f-7773-490e-adcd-46757c738eb7', width=1024, height=768, | ||
guidance_scale=3) | ||
response = await leonardo.post_generations( | ||
prompt="a beautiful necromancer witch resurrects skeletons against " "the backdrop of a burning ruined castle", | ||
num_images=1, | ||
negative_prompt="bright colors, good characters, positive", | ||
model_id="e316348f-7773-490e-adcd-46757c738eb7", | ||
width=1024, | ||
height=768, | ||
guidance_scale=3, | ||
) | ||
print(response) | ||
response = await leonardo.wait_for_image_generation(generation_id=response['sdGenerationJob']['generationId']) | ||
print(json.dumps(response[0]['url'])) | ||
response = await leonardo.wait_for_image_generation(generation_id=response["sdGenerationJob"]["generationId"]) | ||
print(json.dumps(response[0]["url"])) | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Filename: __init__.py | ||
Author: Iliya Vereshchagin | ||
Copyright (c) 2023. All rights reserved. | ||
Created: 16.10.2023 | ||
Last Modified: 17.10.2023 | ||
Description: | ||
This file is init file for speak_and_hear package. | ||
""" |
Oops, something went wrong.