返回提交历史
Modified
.github/workflows/publish-to-pypi.yml
+1
-0
Modified
g4f/gui/client/static/css/style.css
+13
-7
Modified
g4f/gui/client/static/js/chat.v1.js
+5
-0
Modified
g4f/gui/server/api.py
+4
-4
Modified
g4f/gui/server/backend_api.py
+0
-11
Modified
g4f/image/__init__.py
+1
-2
Modified
g4f/tools/files.py
+13
-6
XFEstudio/gpt4free
Update handle media uploads
6c8387f0
代码差异
7 个文件
+37
-30
@@ -9,6 +9,7 @@ jobs:
9
9
build:
10
10
name: Build distribution 📦
11
11
if: startsWith(github.ref, 'refs/tags/')
12
if: github.repository == 'xtekky/gpt4free' && startsWith(github.ref, 'refs/tags/')
12
13
runs-on: ubuntu-latest
13
14
steps:
14
15
- uses: actions/checkout@v4
@@ -859,8 +859,7 @@ select:hover,
859
859
input.model:hover
860
860
.chat-buttons button:hover,
861
861
.stop_generating button:hover,
862
.chat-toolbar .regenerate button:hover,
863
.send-buttons button:hover {
862
.chat-toolbar .regenerate button:hover {
864
863
background-color: var(--button-hover);
865
864
}
866
865
@@ -1445,8 +1444,8 @@ form textarea {
1445
1444
}
1446
1445
1447
1446
#userInput {
1448
min-height: 94px;
1449
height: 94px;
1447
min-height: 90px;
1448
height: 90px;
1450
1449
flex: 1;
1451
1450
padding: 10px 30px;
1452
1451
color: var(--colour-3);
@@ -1544,18 +1543,25 @@ form textarea {
1544
1543
}
1545
1544
.send-buttons {
1546
1545
display: flex;
1547
gap: 10px;
1546
gap: 6px;
1548
1547
flex-direction: column;
1549
1548
}
1550
1549
.chat-footer .send-buttons button {
1551
1550
background: var(--blur-bg);
1552
color: white;
1551
color: var(--colour-3);
1553
1552
padding: 12px 15px;
1554
1553
margin: 0 2px 0 4px;
1555
1554
border-radius: 5px;
1556
1555
cursor: pointer;
1557
border: 1px dashed #e4d4ffa6;
1556
border: 1px dashed var(--conversations);
1557
box-shadow: 1px 1px 1px 0px rgba(0,0,0,0.75);
1558
}
1559
.white .chat-footer .send-buttons button {
1560
border-style: solid;
1561
border-color: var(--blur-border);
1558
1562
}
1559
1563
.chat-footer .send-buttons button:hover {
1560
1564
border-style: solid;
1565
box-shadow: none;
1566
background-color: var(--button-hover);
1561
1567
}
@@ -2619,6 +2619,11 @@ function connectToSSE(url, do_refine, bucket_id) {
2619
2619
inputCount.innerText = `Error: ${data.error.message}`;
2620
2620
paperclip.classList.remove("blink");
2621
2621
fileInput.value = "";
2622
} else if (data.action == "media") {
2623
inputCount.innerText = `File: ${data.filename}`;
2624
const url = `/files/${bucket_id}/media/${data.filename}`;
2625
const media = [{bucket_id: bucket_id, url: url}];
2626
await handle_ask(false, media);
2622
2627
} else if (data.action == "load") {
2623
2628
inputCount.innerText = `Read data: ${formatFileSize(data.size)}`;
2624
2629
} else if (data.action == "refine") {
@@ -182,15 +182,15 @@ class Api:
182
182
elif isinstance(chunk, PreviewResponse):
183
183
yield self._format_json("preview", chunk.to_string())
184
184
elif isinstance(chunk, ImagePreview):
185
yield self._format_json("preview", chunk.to_string(), images=chunk.images, alt=chunk.alt)
186
elif isinstance(chunk, (ImageResponse, VideoResponse)):
185
yield self._format_json("preview", chunk.to_string(), urls=chunk.urls, alt=chunk.alt)
186
elif isinstance(chunk, MediaResponse):
187
187
media = chunk
188
188
if download_media or chunk.get("cookies"):
189
189
chunk.alt = format_image_prompt(kwargs.get("messages"), chunk.alt)
190
tags = [model, kwargs.get("aspect_ratio")]
190
tags = [model, kwargs.get("aspect_ratio"), kwargs.get("resolution"), kwargs.get("width"), kwargs.get("height")]
191
191
media = asyncio.run(copy_media(chunk.get_list(), chunk.get("cookies"), chunk.get("headers"), proxy=proxy, alt=chunk.alt, tags=tags))
192
192
media = ImageResponse(media, chunk.alt) if isinstance(chunk, ImageResponse) else VideoResponse(media, chunk.alt)
193
yield self._format_json("content", str(media), images=chunk.get_list(), alt=chunk.alt)
193
yield self._format_json("content", str(media), urls=chunk.urls, alt=chunk.alt)
194
194
elif isinstance(chunk, SynthesizeData):
195
195
yield self._format_json("synthesize", chunk.get_dict())
196
196
elif isinstance(chunk, TitleGeneration):
@@ -276,17 +276,6 @@ class Backend_Api(Api):
276
276
logger.exception(e)
277
277
return jsonify({"error": {"message": f"{type(e).__name__}: {e}"}}), 500
278
278
279
@app.route('/backend-api/v2/buckets', methods=['GET'])
280
def list_buckets():
281
try:
282
buckets = get_buckets()
283
if buckets is None:
284
return jsonify({"error": {"message": "Error accessing bucket directory"}}), 500
285
sanitized_buckets = [secure_filename(b) for b in buckets]
286
return jsonify(sanitized_buckets), 200
287
except Exception as e:
288
return jsonify({"error": {"message": str(e)}}), 500
289
290
279
@app.route('/backend-api/v2/files/<bucket_id>', methods=['GET', 'DELETE'])
291
280
def manage_files(bucket_id: str):
292
281
bucket_id = secure_filename(bucket_id)
@@ -14,7 +14,6 @@ try:
14
14
except ImportError:
15
15
has_requirements = False
16
16
17
from ..providers.helper import filter_none
18
17
from ..typing import ImageType, Union, Image
19
18
from ..errors import MissingRequirementsError
20
19
@@ -282,7 +281,7 @@ def to_input_audio(audio: ImageType, filename: str = None) -> str:
282
281
raise ValueError("Invalid input audio")
283
282
284
283
def use_aspect_ratio(extra_data: dict, aspect_ratio: str) -> Image:
285
extra_data = filter_none(**extra_data)
284
extra_data = {key: value for key, value in extra_data.items() if value is not None}
286
285
if aspect_ratio == "1:1":
287
286
extra_data = {
288
287
"width": 1024,
@@ -70,6 +70,7 @@ except ImportError:
70
70
71
71
from .web_search import scrape_text
72
72
from ..cookies import get_cookies_dir
73
from ..image import is_allowed_extension
73
74
from ..requests.aiohttp import get_connector
74
75
from ..providers.asyncio import to_sync_generator
75
76
from ..errors import MissingRequirementsError
@@ -448,7 +449,7 @@ async def download_urls(
448
449
if not filename:
449
450
print(f"Failed to get filename for {url}")
450
451
return None
451
if not supports_filename(filename) or filename == DOWNLOADS_FILE:
452
if not is_allowed_extension(filename) and not supports_filename(filename) or filename == DOWNLOADS_FILE:
452
453
return None
453
454
if filename.endswith(".html") and max_depth > 0:
454
455
add_urls = read_links(await response.text(), str(response.url))
@@ -457,10 +458,14 @@ async def download_urls(
457
458
add_urls = [add_url for add_url in add_urls if add_url not in loading_urls]
458
459
[loading_urls.add(add_url) for add_url in add_urls]
459
460
[new_urls.append(add_url) for add_url in add_urls if add_url not in new_urls]
460
target = bucket_dir / filename
461
if is_allowed_extension(filename):
462
target = bucket_dir / "media" / filename
463
target.parent.mkdir(parents=True, exist_ok=True)
464
else:
465
target = bucket_dir / filename
461
466
with target.open("wb") as f:
462
async for chunk in response.content.iter_chunked(4096):
463
if b'<link rel="canonical"' not in chunk:
467
async for chunk in response.content.iter_any():
468
if filename.endswith(".html") and b'<link rel="canonical"' not in chunk:
464
469
f.write(chunk.replace(b'</head>', f'<link rel="canonical" href="{response.url}">\n</head>'.encode()))
465
470
else:
466
471
f.write(chunk)
@@ -538,9 +543,11 @@ def stream_chunks(bucket_dir: Path, delete_files: bool = False, refine_chunks_wi
538
543
else:
539
544
yield chunk
540
545
files_txt = os.path.join(bucket_dir, FILE_LIST)
541
if delete_files and os.path.exists(files_txt):
546
if os.path.exists(files_txt):
542
547
for filename in get_filenames(bucket_dir):
543
if os.path.exists(os.path.join(bucket_dir, filename)):
548
if is_allowed_extension(filename):
549
yield f'data: {json.dumps({"action": "media", "filename": filename})}\n\n'
550
if delete_files and os.path.exists(os.path.join(bucket_dir, filename)):
544
551
os.remove(os.path.join(bucket_dir, filename))
545
552
os.remove(files_txt)
546
553
if event_stream: