mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-10-05 00:12:44 +08:00
Add webview docs and examples, Set webview as default
This commit is contained in:
32
README.md
32
README.md
@@ -41,7 +41,7 @@ As per the survey, here is a list of improvements to come
|
|||||||
- [ ] 🚧 Improve Documentation (in /docs & Guides, Howtos, & Do video tutorials)
|
- [ ] 🚧 Improve Documentation (in /docs & Guides, Howtos, & Do video tutorials)
|
||||||
- [x] Improve the provider status list & updates
|
- [x] Improve the provider status list & updates
|
||||||
- [ ] Tutorials on how to reverse sites to write your own wrapper (PoC only ofc)
|
- [ ] Tutorials on how to reverse sites to write your own wrapper (PoC only ofc)
|
||||||
- [ ] Improve the Bing wrapper. (might write a new wrapper in golang as it is very fast)
|
- [x] Improve the Bing wrapper. (Wait and Retry or reuse conversation)
|
||||||
- [ ] Write a standard provider performance test to improve the stability
|
- [ ] Write a standard provider performance test to improve the stability
|
||||||
- [ ] Potential support and development of local models
|
- [ ] Potential support and development of local models
|
||||||
- [ ] 🚧 Improve compatibility and error handling
|
- [ ] 🚧 Improve compatibility and error handling
|
||||||
@@ -170,7 +170,33 @@ image_url = response.data[0].url
|
|||||||
- New Client API like the OpenAI Python library: [/docs/client](/docs/client.md)
|
- New Client API like the OpenAI Python library: [/docs/client](/docs/client.md)
|
||||||
- Legacy API with python modules: [/docs/legacy](/docs/legacy.md)
|
- Legacy API with python modules: [/docs/legacy](/docs/legacy.md)
|
||||||
|
|
||||||
#### Web UI
|
### Webview GUI
|
||||||
|
|
||||||
|
Open the GUI in a window of your OS. Runs on a local/static/ssl server with a js api. Supports login into the OpenAI Chat, Image Upload and streamed Text Generation.
|
||||||
|
|
||||||
|
Supports all platforms, but only Linux testet.
|
||||||
|
|
||||||
|
1. Install all requirements with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install g4f[webview]
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Follow the OS specific steps here:
|
||||||
|
[pywebview installation](https://pywebview.flowrl.com/guide/installation.html#dependencies)
|
||||||
|
|
||||||
|
3. Run the app with:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from g4f.gui.webview import run_webview
|
||||||
|
run_webview(debug=True)
|
||||||
|
```
|
||||||
|
or execute the following command:
|
||||||
|
```bash
|
||||||
|
python -m g4f.gui.webview -debug
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Webserver
|
||||||
|
|
||||||
To start the web interface, type the following codes in python:
|
To start the web interface, type the following codes in python:
|
||||||
|
|
||||||
@@ -237,7 +263,7 @@ set G4F_PROXY=http://host:port
|
|||||||
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ |  | ❌ |
|
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ |  | ❌ |
|
||||||
| [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ❌ | ✔️ | ✔️ |  | ❌ |
|
| [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ❌ | ✔️ | ✔️ |  | ❌ |
|
||||||
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ |  | ❌ |
|
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ |  | ❌ |
|
||||||
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ✔️ | ✔️ |  | ✔️ |
|
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ❌ | ✔️ |  | ✔️ |
|
||||||
| [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ |  | ✔️ |
|
| [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ |  | ✔️ |
|
||||||
| [beta.theb.ai](https://beta.theb.ai) | `g4f.Provider.Theb` | ✔️ | ✔️ | ✔️ |  | ❌ |
|
| [beta.theb.ai](https://beta.theb.ai) | `g4f.Provider.Theb` | ✔️ | ✔️ | ✔️ |  | ❌ |
|
||||||
| [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ✔️ | ✔️ |  | ❌ |
|
| [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ✔️ | ✔️ |  | ❌ |
|
||||||
|
@@ -414,7 +414,7 @@ async def stream_generate(
|
|||||||
image_request = await upload_image(
|
image_request = await upload_image(
|
||||||
session,
|
session,
|
||||||
image,
|
image,
|
||||||
"Balanced" if Tones.copilot == "Copilot" else tone,
|
"Balanced" if tone == Tones.copilot else tone,
|
||||||
headers
|
headers
|
||||||
) if image else None
|
) if image else None
|
||||||
async with session.ws_connect(
|
async with session.ws_connect(
|
||||||
|
@@ -240,26 +240,26 @@ async function add_message_chunk(message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cameraInput?.addEventListener("click", (e) => {
|
// fileInput?.addEventListener("click", (e) => {
|
||||||
if (window?.pywebview) {
|
// if (window?.pywebview) {
|
||||||
e.preventDefault();
|
// e.preventDefault();
|
||||||
pywebview.api.choose_file();
|
// pywebview.api.choose_file();
|
||||||
}
|
// }
|
||||||
})
|
// });
|
||||||
|
|
||||||
cameraInput?.addEventListener("click", (e) => {
|
cameraInput?.addEventListener("click", (e) => {
|
||||||
if (window?.pywebview) {
|
if (window?.pywebview) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
pywebview.api.take_picture();
|
pywebview.api.take_picture();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
imageInput?.addEventListener("click", (e) => {
|
imageInput?.addEventListener("click", (e) => {
|
||||||
if (window?.pywebview) {
|
if (window?.pywebview) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
pywebview.api.choose_image();
|
pywebview.api.choose_image();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
const ask_gpt = async () => {
|
const ask_gpt = async () => {
|
||||||
regenerate.classList.add(`regenerate-hidden`);
|
regenerate.classList.add(`regenerate-hidden`);
|
||||||
|
@@ -19,12 +19,12 @@ try:
|
|||||||
filters=[["Image", "*.jpg", "*.jpeg", "*.png", "*.webp", "*.svg"]],
|
filters=[["Image", "*.jpg", "*.jpeg", "*.png", "*.webp", "*.svg"]],
|
||||||
)
|
)
|
||||||
has_plyer = True
|
has_plyer = True
|
||||||
except (ImportError, NameError):
|
except ImportError:
|
||||||
has_plyer = False
|
has_plyer = False
|
||||||
try:
|
try:
|
||||||
from android.runnable import run_on_ui_thread
|
from android.runnable import run_on_ui_thread
|
||||||
from android.storage import app_storage_path
|
import android.permissions
|
||||||
from android.permissions import request_permissions, Permission
|
from android.permissions import Permission
|
||||||
from android.permissions import _RequestPermissionsManager
|
from android.permissions import _RequestPermissionsManager
|
||||||
_RequestPermissionsManager.register_callback()
|
_RequestPermissionsManager.register_callback()
|
||||||
from .android_gallery import user_select_image
|
from .android_gallery import user_select_image
|
||||||
@@ -161,7 +161,7 @@ class Api():
|
|||||||
|
|
||||||
def request_permissions(self):
|
def request_permissions(self):
|
||||||
if has_android:
|
if has_android:
|
||||||
request_permissions([
|
android.permissions.request_permissions([
|
||||||
Permission.CAMERA,
|
Permission.CAMERA,
|
||||||
Permission.READ_EXTERNAL_STORAGE,
|
Permission.READ_EXTERNAL_STORAGE,
|
||||||
Permission.WRITE_EXTERNAL_STORAGE
|
Permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
@@ -16,6 +16,7 @@ import g4f.debug
|
|||||||
|
|
||||||
def run_webview(
|
def run_webview(
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
|
ssl: bool = True,
|
||||||
storage_path: str = None
|
storage_path: str = None
|
||||||
):
|
):
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
@@ -36,7 +37,7 @@ def run_webview(
|
|||||||
private_mode=False,
|
private_mode=False,
|
||||||
storage_path=storage_path,
|
storage_path=storage_path,
|
||||||
debug=debug,
|
debug=debug,
|
||||||
ssl=True
|
ssl=ssl
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
18
setup.py
18
setup.py
@@ -18,23 +18,24 @@ EXTRA_REQUIRE = {
|
|||||||
'all': [
|
'all': [
|
||||||
"curl_cffi>=0.6.2",
|
"curl_cffi>=0.6.2",
|
||||||
"certifi",
|
"certifi",
|
||||||
"async-property", # openai
|
#"py-arkose-generator", # not working
|
||||||
"py-arkose-generator", # openai
|
|
||||||
"browser_cookie3", # get_cookies
|
"browser_cookie3", # get_cookies
|
||||||
"PyExecJS", # GptForLove
|
"PyExecJS", # GptForLove
|
||||||
"duckduckgo-search>=5.0" ,# internet.search
|
"duckduckgo-search>=5.0" ,# internet.search
|
||||||
"beautifulsoup4", # internet.search and bing.create_images
|
"beautifulsoup4", # internet.search and bing.create_images
|
||||||
"brotli", # openai
|
"brotli", # openai
|
||||||
"platformdirs", # webdriver
|
#"undetected-chromedriver>=3.5.5", # webdriver
|
||||||
"undetected-chromedriver>=3.5.5", # webdriver
|
#"setuptools", # webdriver
|
||||||
"setuptools", # webdriver
|
"pywebview",
|
||||||
|
"platformdirs",
|
||||||
|
"plyer",
|
||||||
"aiohttp_socks", # proxy
|
"aiohttp_socks", # proxy
|
||||||
"pillow", # image
|
"pillow", # image
|
||||||
"cairosvg", # svg image
|
"cairosvg", # svg image
|
||||||
"werkzeug", "flask", # gui
|
"werkzeug", "flask", # gui
|
||||||
"loguru", "fastapi",
|
"loguru", "fastapi",
|
||||||
"uvicorn", "nest_asyncio", # api
|
"uvicorn", "nest_asyncio", # api
|
||||||
"selenium-wire"
|
#"selenium-wire"
|
||||||
],
|
],
|
||||||
"image": [
|
"image": [
|
||||||
"pillow",
|
"pillow",
|
||||||
@@ -47,6 +48,11 @@ EXTRA_REQUIRE = {
|
|||||||
"setuptools",
|
"setuptools",
|
||||||
"selenium-wire"
|
"selenium-wire"
|
||||||
],
|
],
|
||||||
|
"webview": [
|
||||||
|
"webview",
|
||||||
|
"platformdirs",
|
||||||
|
"plyer"
|
||||||
|
],
|
||||||
"openai": [
|
"openai": [
|
||||||
"async-property",
|
"async-property",
|
||||||
"py-arkose-generator",
|
"py-arkose-generator",
|
||||||
|
Reference in New Issue
Block a user