Git Product home page Git Product logo

craiyon.py's Introduction

FireHead90544

Hello! I'm Rudransh 👋

I am a self-taught developer from India who enjoys writing code, listening to music, and watching anime. Reading light novels and manga is yet another hobby of mine. I'm just a cool nerd who's into tech and programming. Currently, I am pursuing my bachelor's degree in Artificial Intelligence & Machine Learning. And as always, I'm just a typical "relatable" guy you can't relate to.

Stats

Stats Streak Languages Languages

Tools & Tech

Languages



Libraries & Frameworks





Databases

Deployment


Version Control & Tools



·   To get in touch, you may find AllMyLinks here   ·

craiyon.py's People

Contributors

firehead90544 avatar mdm9300404 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

craiyon.py's Issues

Why use a class for craiyon.py?

I think it's pretty pointless. It isn't used anywhere else and there's no reason to really use a class for it. Bad use of OOP

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Just recently got the time to test it out again for myself. I ran 'pip install -U craiyon.py', so it's updated. Unfortunately, this still seems to be a problem. The error of 'json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)' still persists. I'm unable to get something as simple as the following to work:

from craiyon import Craiyon
generator = Craiyon()
result = generator.generate("Photorealistic image of shrek eating earth", negative_prompt="spoon", model_type="art")
print(result.description)
result.save_images()

This, of course, is just one of the examples given in the Craiyon API documentation on how to use it. Any fix would be appreciated!

Originally posted by @IbyCodes in #18 (comment)

cannot identify image file <_io.BytesIO object

Hi! Thanks for the API!

In your example: "Use the images in your code without saving", when I tried to run I obtained the following error:

UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002AF3B048AE0>

The error points to the line: 5 image = Image.open(BytesIO(base64.decodebytes(i.encode("utf-8"))))

Do you know how to fix this?
Thanks in advance!

v3 image generation throws a 403 error

When trying to create images using the standard Craiyon client, it throws a 403 error from axios. Curious if this is caused by not having an API key with a paid subscription, or if they are down. Has been happening for at least 3 days now.
Screenshot 2023-08-02 121148

API_TOKEN

Craiyon's api_token seems to change whenever I sign in to the service, which breaks already working code. Is there any stable way of getting a persistent api_token instead?

Error while used for discord bot

Code:

@app_commands.command(name="texttoimg",description="Give your prompt to generate image")
    async def texttoimg(self,interaction: discord.Interaction,prompt: str):
        # await interaction.response.send_message("Generating: "+prompt+" ....")
        generator = Craiyon()
        generated_images = await generator.async_generate(prompt)
        b64_list = await craiyon_utils.async_encode_base64(generated_images.images) 
        
        images1 = []
        for index, image in enumerate(b64_list):
            img_bytes = BytesIO(base64.b64decode(image)) 
            # image = discord.File(img_bytes)
            image =  discord.File(img_bytes)
            image.filename = f"result{index}.webp"
            images1.append(image)         
        await interaction.response.send_message(files=images1)

Output:

image

If i print in console it works well, but doesn't send img to discord

urls feature not working

generator = Craiyon() # Instantiates the api wrapper
result = generator.generate("Photorealistic image of shrek eating earth")

print(result.images) # Prints a list of the Direct Image URLs hosted on https://img.craiyon.com

for url in result.images:
print(url)

when i run the code i get this error ;
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "e:\FILES\Documents\Python projects\ELLIOT-BOT\gen 2\advanced_AI.py", line 153, in
result = generator.generate("Photorealistic image of shrek eating earth")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\craiyon\craiyon.py", line 48, in generate
resp = resp.json()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

i dont know here is the prob here

Unexpected minetype

Ignoring exception in on_application_command_error
Traceback (most recent call last):
File "D:\Programmierung\Python\Projekte\MiniGamesBot\venv\lib\site-packages\nextcord\client.py", line 490, in _run_event
await coro(*args, **kwargs)
File "D:\Programmierung\Python\Projekte\MiniGamesBot\bot\bot.py", line 193, in on_application_command_error
raise error
File "D:\Programmierung\Python\Projekte\MiniGamesBot\venv\lib\site-packages\nextcord\application_command.py", line 895, in invoke_callback_with_hooks
await self(interaction, *args, **kwargs)
File "D:\Programmierung\Python\Projekte\MiniGamesBot\venv\lib\site-packages\cooldowns\cooldown.py", line 109, in inner
result = await func(*args, **kwargs)
File "D:\Programmierung\Python\Projekte\MiniGamesBot\bot\cogs\Ki stuff.py", line 83, in imagine
result = await generator.async_generate(prompt)
File "D:\Programmierung\Python\Projekte\MiniGamesBot\venv\lib\site-packages\craiyon\craiyon.py", line 76, in async_generate
resp = await resp.json()
File "D:\Programmierung\Python\Projekte\MiniGamesBot\venv\lib\site-packages\aiohttp\client_reqrep.py", line 1104, in json
raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.craiyon.com/v3')
ERROR:0, message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', url=URL('https://api.craiyon.com/v3')

Json Decode Error

Hi guys,
i have a problem.

File "/mount/src/generatore-arte-ia/Craiyon.py", line 13, in Generate
    result = generator.generate(request)
File "/home/adminuser/venv/lib/python3.9/site-packages/craiyon/craiyon.py", line 182, in generate
    return GeneratedImages(resp.json()['images'], model="v1")
File "/home/adminuser/venv/lib/python3.9/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

I have try v3 and v1 in all version ( async and not) and the result is always this .

How i can resolve ?

AttributeError: 'Craiyon' object has no attribute 'async_generate'

hello, i have some problems.
i am making discord bot, and i can't call async_generate

here's my code:

async def dall_e_mini(ctx, prompt: str):
    await ctx.response.defer()
    craiyon_gen = Craiyon()

    result = await craiyon_gen.async_generate(prompt)
    await result.async_save_images(path = f".\\temp\\{ctx.author.id}")

    files_to_upload = []

    for file in os.listdir(f'.\\temp\\{ctx.author.id}'):
        files_to_upload.append(discord.File(f'.\\temp\\{ctx.author.id}\\{file}'))
    
    await ctx.send(f'**{prompt}** - {ctx.author.mention}', files=files_to_upload)```

what i do not right?
i'm using Python 3.10.7

v2

What do i have to modify in order to use the V2 model?

`from craiyon import Craiyon
from PIL import Image
from io import BytesIO
import streamlit as st
import base64

def Generate(request):
generator = Craiyon() # Instantiates the api wrapper
result = generator.generate(request) # Generates 9 images by default
images = result.images
return images

generator = Craiyon()
request = "a dragon on a motorbike"
image_files = Generate(request)
st.image(Image.open(BytesIO(base64.decodebytes(image_files[0].encode("utf-8")))))`

V3

Pls update it to v3

Mimetype error with async functions

The switch to CloudScraper worked for the standard generate function. However, the async functions are still throwing Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8'.

Recommend using a library like aiocfscrape to support CloudScraper's functionality for the async functions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.