Skip to content

Commit 41ac0dd

Browse files
committed
Add support for image generation
1 parent 985ae9d commit 41ac0dd

File tree

10 files changed

+230
-204
lines changed

10 files changed

+230
-204
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,5 @@ make-*.py
169169
*.deb
170170
*.spec
171171
assets/deb/DEBIAN/control
172-
assets/deb/usr/share/applications/pytgpt.desktop
172+
assets/deb/usr/share/applications/pytgpt.desktop
173+
*.jpeg

docs/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,10 @@ For instance:
421421

422422
**What's new?**
423423

424-
- fix: llama2. #34
424+
- fix: llama2. #34
425+
426+
## v0.5.3
427+
428+
**What's new?**
429+
430+
- added: Support for image generation.

docs/README.md

Lines changed: 53 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Submit any bug at https://github.com/Simatwa/python-tgpt/issues/new
5050
"""
5151
```
5252
53-
This project enables seamless interaction with over **45 free LLM providers** without requiring an API Key.
53+
This project enables seamless interaction with over **45 free LLM providers** without requiring an API Key as well generating images.
5454
5555
The name *python-tgpt* draws inspiration from its parent project [tgpt](https://github.com/aandrew-me/tgpt), which operates on [Golang](https://go.dev/). Through this Python adaptation, users can effortlessly engage with a number of free LLMs available, fostering a smoother AI interaction experience.
5656
@@ -69,6 +69,7 @@ The name *python-tgpt* draws inspiration from its parent project [tgpt](https://
6969
- 🧠 Multiple LLM providers - **45+**
7070
- 🎯 Customizable script generation and execution
7171
- 🔌 Offline support for Large Language Models
72+
- 🎨 Image generation capabilities
7273
7374
## Providers
7475
@@ -86,158 +87,19 @@ These are simply the hosts of the LLMs, which include:
8687
12. [gpt4all](https://gpt4all.io) *(Offline)*
8788
13. [Poe](poe.com) - Poe|Quora *(Session ID required)*
8889
90+
8991
<details>
9092
9193
<summary>
9294
9395
41+ Other models proudly offered by [gpt4free](https://github.com/xtekky/gpt4free).
9496
97+
</summary>
98+
9599
- To list working providers run:
96100
```sh
97101
$ pytgpt gpt4free test -y
98102
```
99-
100-
</summary>
101-
102-
- AiChatOnline
103-
- [Aura](https://openchat.team)
104-
- [Bard](https://bard.google.com/)
105-
- [Bing](https://bing.com)
106-
- [ChatBase](https://www.chatbase.co/)
107-
- [ChatForAi](https://chatforai.store/)
108-
- [Chatgpt4Online](https://chatgpt4online.org)
109-
- [ChatgptAi](https://chatgpt.ai/)
110-
- [ChatgptDemo](https://chat.chatgptdemo.net)
111-
- [ChatgptNext](https://www.chatgpt-free.c)
112-
- [Chatxyz](https://chat.3211000.xyz)
113-
- [DeepInfra](https://deepinfra.co)
114-
- [FakeGpt](https://chat-shared2.zhile.io/)
115-
- [FreeChatgpt](https://free.chatgpt.org.uk)
116-
- [GPTalk](https://gptalk.net/)
117-
- [GeekGpt](https://chat.geekgpt.org)
118-
- [GeminiProChat](https://geminiprochat.com)
119-
- Gpt6
120-
- [GptChatly](https://gptchatly.com)
121-
- [GptForLove](https://ai18.gptforlove.com/)
122-
- [GptGo](https://gptgo.ai/)
123-
- GptTalkRu
124-
- [Hashnode](https://hashnode.com/)
125-
- [HuggingChat](https://huggingface.co/chat)
126-
- Koala
127-
- [Liaobots](https://liaobots.site)
128-
- [Llama2](https://www.llama2.ai/)
129-
- [MyShell](https://app.myshell.ai/chat)
130-
- OnlineGpt
131-
- OpenaiChat
132-
- PerplexityAi
133-
- [Phind](https://www.phind.com)
134-
- Pi
135-
- Poe
136-
- [Raycast](https://raycast.com)
137-
- TalkAi
138-
- [Theb](https://theb.ai/)
139-
- ThebApi
140-
- [You](https://you.com/)
141-
- [Yqcloud](https://chat9.yqcloud.top/)
142-
143-
<details>
144-
145-
<summary>
146-
147-
All models. *(Include not working)*
148-
149-
</summary>
150-
151-
1. [AItianhu](https://www.aitianhu.com)
152-
2. [AItianhuSpace](https://chat3.aiyunos.top/)
153-
3. [Acytoo](https://chat.acytoo.com)
154-
4. [AiAsk](https://e.aiask.me)
155-
5. [AiChatOnline](https://aichatonline.org)
156-
6. [AiChatting](https://www.aichatting.net)
157-
7. [AiService](https://aiservice.vercel.app/)
158-
8. [Aibn](https://aibn.cc)
159-
9. [Aichat](https://chat-gpt.org/chat)
160-
10. [Ails](https://ai.ls)
161-
11. [Aivvm](https://chat.aivvm.com)
162-
12. AsyncGeneratorProvider
163-
13. AsyncProvider
164-
14. [Aura](https://openchat.team)
165-
15. [Bard](https://bard.google.com)
166-
16. BaseProvider
167-
17. [Berlin](https://ai.berlin4h.top)
168-
18. [Bestim](https://chatgpt.bestim.org)
169-
19. [Bing](https://bing.com/chat)
170-
20. [ChatAiGpt](https://chataigpt.org)
171-
21. [ChatAnywhere](https://chatanywhere.cn)
172-
22. [ChatBase](https://www.chatbase.co)
173-
23. [ChatForAi](https://chatforai.store)
174-
24. [Chatgpt4Online](https://chatgpt4online.org)
175-
25. [ChatgptAi](https://chatgpt.ai)
176-
26. [ChatgptDemo](https://chat.chatgptdemo.net)
177-
27. [ChatgptDemoAi](https://chat.chatgptdemo.ai)
178-
28. [ChatgptDuo](https://chatgptduo.com)
179-
29. [ChatgptFree](https://chatgptfree.ai)
180-
30. [ChatgptLogin](https://chatgptlogin.ai)
181-
31. [ChatgptNext](https://www.chatgpt-free.cc)
182-
32. [ChatgptX](https://chatgptx.de)
183-
33. [Chatxyz](https://chat.3211000.xyz)
184-
34. [CodeLinkAva](https://ava-ai-ef611.web.app)
185-
35. CreateImagesProvider
186-
36. [Cromicle](https://cromicle.top)
187-
37. [DeepInfra](https://deepinfra.com)
188-
38. [DfeHub](https://chat.dfehub.com/)
189-
39. [EasyChat](https://free.easychat.work)
190-
40. [Equing](https://next.eqing.tech/)
191-
41. [FakeGpt](https://chat-shared2.zhile.io)
192-
42. [FastGpt](https://chat9.fastgpt.me/)
193-
43. [Forefront](https://forefront.com)
194-
44. [FreeChatgpt](https://free.chatgpt.org.uk)
195-
45. [FreeGpt](https://freegpts1.aifree.site/)
196-
46. [GPTalk](https://gptalk.net)
197-
47. [GeekGpt](https://chat.geekgpt.org)
198-
48. [GeminiProChat](https://geminiprochat.com)
199-
49. [GetGpt](https://chat.getgpt.world/)
200-
50. [Gpt6](https://gpt6.ai)
201-
51. [GptChatly](https://gptchatly.com)
202-
52. [GptForLove](https://ai18.gptforlove.com)
203-
53. [GptGo](https://gptgo.ai)
204-
54. [GptGod](https://gptgod.site)
205-
55. [GptTalkRu](https://gpttalk.ru)
206-
56. [H2o](https://gpt-gm.h2o.ai)
207-
57. [Hashnode](https://hashnode.com)
208-
58. [HuggingChat](https://huggingface.co/chat)
209-
59. [Koala](https://koala.sh)
210-
60. [Komo](https://komo.ai/api/ask)
211-
61. [Liaobots](https://liaobots.site)
212-
62. [Llama2](https://www.llama2.ai)
213-
63. [Lockchat](http://supertest.lockchat.app)
214-
64. [MikuChat](https://ai.okmiku.com)
215-
65. [MyShell](https://app.myshell.ai/chat)
216-
66. [Myshell](https://app.myshell.ai/chat)
217-
67. [OnlineGpt](https://onlinegpt.org)
218-
68. [Opchatgpts](https://opchatgpts.net)
219-
69. [OpenAssistant](https://open-assistant.io/chat)
220-
70. [OpenaiChat](https://chat.openai.com)
221-
71. [PerplexityAi](https://www.perplexity.ai)
222-
72. [Phind](https://www.phind.com)
223-
73. [Pi](https://pi.ai/talk)
224-
74. [Poe](https://poe.com)
225-
75. [Raycast](https://raycast.com)
226-
76. RetryProvider
227-
77. [TalkAi](https://talkai.info)
228-
78. [Theb](https://beta.theb.ai)
229-
79. [ThebApi](https://theb.ai)
230-
80. [V50](https://p5.v50.ltd)
231-
81. [Vercel](https://sdk.vercel.ai)
232-
82. [Vitalentum](https://app.vitalentum.io)
233-
83. [Wewordle](https://wewordle.org)
234-
84. [Wuguokai](https://chat.wuguokai.xyz)
235-
85. [Ylokh](https://chat.ylokh.xyz)
236-
86. [You](https://you.com)
237-
87. [Yqcloud](https://chat9.yqcloud.top/)
238-
239-
</details>
240-
241103
</details>
242104
243105
## Prerequisites
@@ -511,6 +373,54 @@ Utilize the `--disable-conversation` flag in the console to achieve the same fun
511373
> [!CAUTION]
512374
> **Bard** autohandles context due to the obvious reason; the `is_conversation` parameter is not necessary at all hence not required when initializing the class. Also be informed that majority of providers offered by *gpt4free* requires *Google Chrome* inorder to function.
513375
376+
### Image Generation
377+
378+
This has been made possible with [pollination.ai](https://pollination.ai).
379+
```sh
380+
$ pytgpt imager "<prompt>"
381+
# e.g pytgpt imager "Coding bot"
382+
```
383+
384+
<details>
385+
386+
<summary>
387+
Developers
388+
</summary>
389+
390+
```python
391+
from pytgpt.imager import Imager
392+
393+
img = Imager()
394+
395+
generated_img = img.generate('Coding bot') # [bytes]
396+
397+
img.save(generated_img)
398+
```
399+
400+
<details>
401+
402+
<summary>
403+
Download Multiple Images
404+
</summary>
405+
406+
```python
407+
408+
from pytgpt.imager import Imager
409+
410+
img = Imager()
411+
412+
img_generator = img.generate('Coding bot', amount=3, stream=True)
413+
414+
img.save(img_generator)
415+
416+
# RAM friendly
417+
```
418+
419+
</details>
420+
421+
422+
</details>
423+
514424
### Advanced Usage of Placeholders
515425
516426
The `generate` functionality has been enhanced starting from *v0.3.0* to enable comprehensive utilization of the `--with-copied` option and support for accepting piped inputs. This improvement introduces placeholders, offering dynamic values for more versatile interactions.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
setup(
4040
name="python-tgpt",
41-
version="0.5.2",
41+
version="0.5.3",
4242
license="MIT",
4343
author="Smartwa",
4444
maintainer="Smartwa",

src/pytgpt/console.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
from rich.live import Live
2424
from rich.table import Table
2525
from rich.prompt import Prompt
26+
from rich.progress import Progress
2627
from typing import Iterator
2728
from pytgpt.utils import Optimizers
2829
from pytgpt.utils import default_path
2930
from pytgpt.utils import AwesomePrompts
3031
from pytgpt.utils import RawDog
32+
from pytgpt.imager import Imager
3133
from WebChatGPT.console import chat as webchatgpt
3234
from colorama import Fore
3335
from colorama import init as init_colorama
@@ -2182,6 +2184,62 @@ def test(
21822184
rich.print(table)
21832185

21842186

2187+
class ImageGen:
2188+
2189+
@staticmethod
2190+
@click.command(context_settings=this.context_settings)
2191+
@click.argument("prompt")
2192+
@click.option(
2193+
"-d",
2194+
"--directory",
2195+
type=click.Path(exists=True),
2196+
help="Folder for saving the images",
2197+
default=os.getcwd(),
2198+
)
2199+
@click.option(
2200+
"-a",
2201+
"--amount",
2202+
type=click.IntRange(1, 100),
2203+
help="Total images to be generated",
2204+
default=1,
2205+
)
2206+
@click.option("-n", "--name", help="Name for the generated images")
2207+
@click.option(
2208+
"-t",
2209+
"--timeout",
2210+
type=click.IntRange(5, 300),
2211+
help="Http request timeout in seconds",
2212+
)
2213+
@click.option("-p", "--proxy", help="Http request proxy")
2214+
@click.option(
2215+
"-nd",
2216+
"--no-additives",
2217+
is_flag=True,
2218+
help="Disable prompt altering for effective image generation",
2219+
)
2220+
@click.option("-q", "--quiet", is_flag=True, help="Suppress progress bar")
2221+
@click.help_option("-h", "--help")
2222+
def generate_image(
2223+
prompt, directory, amount, name, timeout, proxy, no_additives, quiet
2224+
):
2225+
"""Generate images with pollination.ai"""
2226+
with Progress() as progress:
2227+
task = progress.add_task(
2228+
f"[cyan]Generating ...[{amount}]",
2229+
total=amount,
2230+
visible=quiet == False,
2231+
)
2232+
imager = Imager(timeout=timeout, proxies=proxy if proxy else {})
2233+
for image in imager.generate(
2234+
prompt=prompt,
2235+
amount=amount,
2236+
additives=no_additives == False,
2237+
stream=True,
2238+
):
2239+
imager.save([image], name=name, dir=directory)
2240+
progress.update(task, advance=1)
2241+
2242+
21852243
class Utils:
21862244
"""Utilities command"""
21872245

@@ -2276,6 +2334,9 @@ def make_commands():
22762334
EntryGroup.awesome.add_command(Awesome.update)
22772335
EntryGroup.awesome.add_command(Awesome.whole)
22782336

2337+
# Image generator
2338+
EntryGroup.tgpt2_.add_command(ImageGen.generate_image, "imager")
2339+
22792340

22802341
# @this.handle_exception
22812342
def main(*args):

src/pytgpt/gpt4free/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
from time import time
77
from threading import Thread as thr
88
from functools import wraps
9-
import datetime
109
from rich.progress import Progress
11-
import click
1210
import logging
1311

1412
results_path = Path(default_path) / "provider_test.json"
@@ -88,7 +86,7 @@ def __init__(
8886
pass
8987
else:
9088
self.__log(
91-
30, f"Dropping provider - {provider} - [Selenium dependent]"
89+
10, f"Dropping provider - {provider} - [Selenium dependent]"
9290
)
9391
self.working_providers.remove(provider)
9492

0 commit comments

Comments
 (0)