Skip to content

Commit

Permalink
Merge pull request #1277 from open-webui/dev
Browse files Browse the repository at this point in the history
0.1.115
  • Loading branch information
tjbck committed Mar 24, 2024
2 parents 2fa9495 + 4c95989 commit ac294a7
Show file tree
Hide file tree
Showing 53 changed files with 5,406 additions and 5,689 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

# Logs
logs
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.115] - 2024-03-24

### Added

- **🔍 Custom Model Selector**: Easily find and select custom models with the new search filter feature.
- **🛑 Cancel Model Download**: Added the ability to cancel model downloads.
- **🎨 Image Generation ComfyUI**: Image generation now supports ComfyUI.
- **🌟 Updated Light Theme**: Updated the light theme for a fresh look.
- **🌍 Additional Language Support**: Now supporting Bulgarian, Italian, Portuguese, Japanese, and Dutch.

### Fixed

- **🔧 Fixed Broken Experimental GGUF Upload**: Resolved issues with experimental GGUF upload functionality.

### Changed

- **🔄 Vector Storage Reset Button**: Moved the reset vector storage button to document settings.

## [0.1.114] - 2024-03-20

### Added
Expand Down
12 changes: 8 additions & 4 deletions backend/apps/audio/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import logging
from fastapi import (
FastAPI,
Request,
Expand All @@ -21,7 +22,10 @@
)
from utils.misc import calculate_sha256

from config import CACHE_DIR, UPLOAD_DIR, WHISPER_MODEL, WHISPER_MODEL_DIR
from config import SRC_LOG_LEVELS, CACHE_DIR, UPLOAD_DIR, WHISPER_MODEL, WHISPER_MODEL_DIR

log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["AUDIO"])

app = FastAPI()
app.add_middleware(
Expand All @@ -38,7 +42,7 @@ def transcribe(
file: UploadFile = File(...),
user=Depends(get_current_user),
):
print(file.content_type)
log.info(f"file.content_type: {file.content_type}")

if file.content_type not in ["audio/mpeg", "audio/wav"]:
raise HTTPException(
Expand All @@ -62,7 +66,7 @@ def transcribe(
)

segments, info = model.transcribe(file_path, beam_size=5)
print(
log.info(
"Detected language '%s' with probability %f"
% (info.language, info.language_probability)
)
Expand All @@ -72,7 +76,7 @@ def transcribe(
return {"text": transcript.strip()}

except Exception as e:
print(e)
log.exception(e)

raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
120 changes: 107 additions & 13 deletions backend/apps/images/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@
get_current_user,
get_admin_user,
)

from apps.images.utils.comfyui import ImageGenerationPayload, comfyui_generate_image
from utils.misc import calculate_sha256
from typing import Optional
from pydantic import BaseModel
from pathlib import Path
import uuid
import base64
import json
import logging

from config import SRC_LOG_LEVELS, CACHE_DIR, AUTOMATIC1111_BASE_URL, COMFYUI_BASE_URL

from config import CACHE_DIR, AUTOMATIC1111_BASE_URL

log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["IMAGES"])

IMAGE_CACHE_DIR = Path(CACHE_DIR).joinpath("./image/generations/")
IMAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True)
Expand All @@ -49,6 +55,8 @@


app.state.AUTOMATIC1111_BASE_URL = AUTOMATIC1111_BASE_URL
app.state.COMFYUI_BASE_URL = COMFYUI_BASE_URL


app.state.IMAGE_SIZE = "512x512"
app.state.IMAGE_STEPS = 50
Expand All @@ -71,32 +79,48 @@ async def update_config(form_data: ConfigUpdateForm, user=Depends(get_admin_user
return {"engine": app.state.ENGINE, "enabled": app.state.ENABLED}


class UrlUpdateForm(BaseModel):
url: str
class EngineUrlUpdateForm(BaseModel):
AUTOMATIC1111_BASE_URL: Optional[str] = None
COMFYUI_BASE_URL: Optional[str] = None


@app.get("/url")
async def get_automatic1111_url(user=Depends(get_admin_user)):
return {"AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL}
async def get_engine_url(user=Depends(get_admin_user)):
return {
"AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL,
"COMFYUI_BASE_URL": app.state.COMFYUI_BASE_URL,
}


@app.post("/url/update")
async def update_automatic1111_url(
form_data: UrlUpdateForm, user=Depends(get_admin_user)
async def update_engine_url(
form_data: EngineUrlUpdateForm, user=Depends(get_admin_user)
):

if form_data.url == "":
if form_data.AUTOMATIC1111_BASE_URL == None:
app.state.AUTOMATIC1111_BASE_URL = AUTOMATIC1111_BASE_URL
else:
url = form_data.url.strip("/")
url = form_data.AUTOMATIC1111_BASE_URL.strip("/")
try:
r = requests.head(url)
app.state.AUTOMATIC1111_BASE_URL = url
except Exception as e:
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))

if form_data.COMFYUI_BASE_URL == None:
app.state.COMFYUI_BASE_URL = COMFYUI_BASE_URL
else:
url = form_data.COMFYUI_BASE_URL.strip("/")

try:
r = requests.head(url)
app.state.COMFYUI_BASE_URL = url
except Exception as e:
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e))

return {
"AUTOMATIC1111_BASE_URL": app.state.AUTOMATIC1111_BASE_URL,
"COMFYUI_BASE_URL": app.state.COMFYUI_BASE_URL,
"status": True,
}

Expand Down Expand Up @@ -186,6 +210,18 @@ def get_models(user=Depends(get_current_user)):
{"id": "dall-e-2", "name": "DALL·E 2"},
{"id": "dall-e-3", "name": "DALL·E 3"},
]
elif app.state.ENGINE == "comfyui":

r = requests.get(url=f"{app.state.COMFYUI_BASE_URL}/object_info")
info = r.json()

return list(
map(
lambda model: {"id": model, "name": model},
info["CheckpointLoaderSimple"]["input"]["required"]["ckpt_name"][0],
)
)

else:
r = requests.get(
url=f"{app.state.AUTOMATIC1111_BASE_URL}/sdapi/v1/sd-models"
Expand All @@ -207,6 +243,8 @@ async def get_default_model(user=Depends(get_admin_user)):
try:
if app.state.ENGINE == "openai":
return {"model": app.state.MODEL if app.state.MODEL else "dall-e-2"}
elif app.state.ENGINE == "comfyui":
return {"model": app.state.MODEL if app.state.MODEL else ""}
else:
r = requests.get(url=f"{app.state.AUTOMATIC1111_BASE_URL}/sdapi/v1/options")
options = r.json()
Expand All @@ -221,10 +259,12 @@ class UpdateModelForm(BaseModel):


def set_model_handler(model: str):

if app.state.ENGINE == "openai":
app.state.MODEL = model
return app.state.MODEL
if app.state.ENGINE == "comfyui":
app.state.MODEL = model
return app.state.MODEL
else:
r = requests.get(url=f"{app.state.AUTOMATIC1111_BASE_URL}/sdapi/v1/options")
options = r.json()
Expand Down Expand Up @@ -266,6 +306,23 @@ def save_b64_image(b64_str):
with open(file_path, "wb") as f:
f.write(img_data)

return image_id
except Exception as e:
log.error(f"Error saving image: {e}")
return None


def save_url_image(url):
image_id = str(uuid.uuid4())
file_path = IMAGE_CACHE_DIR.joinpath(f"{image_id}.png")

try:
r = requests.get(url)
r.raise_for_status()

with open(file_path, "wb") as image_file:
image_file.write(r.content)

return image_id
except Exception as e:
print(f"Error saving image: {e}")
Expand All @@ -278,6 +335,8 @@ def generate_image(
user=Depends(get_current_user),
):

width, height = tuple(map(int, app.state.IMAGE_SIZE.split("x")))

r = None
try:
if app.state.ENGINE == "openai":
Expand Down Expand Up @@ -315,12 +374,47 @@ def generate_image(

return images

elif app.state.ENGINE == "comfyui":

data = {
"prompt": form_data.prompt,
"width": width,
"height": height,
"n": form_data.n,
}

if app.state.IMAGE_STEPS != None:
data["steps"] = app.state.IMAGE_STEPS

if form_data.negative_prompt != None:
data["negative_prompt"] = form_data.negative_prompt

data = ImageGenerationPayload(**data)

res = comfyui_generate_image(
app.state.MODEL,
data,
user.id,
app.state.COMFYUI_BASE_URL,
)
print(res)

images = []

for image in res["data"]:
image_id = save_url_image(image["url"])
images.append({"url": f"/cache/image/generations/{image_id}.png"})
file_body_path = IMAGE_CACHE_DIR.joinpath(f"{image_id}.json")

with open(file_body_path, "w") as f:
json.dump(data.model_dump(exclude_none=True), f)

print(images)
return images
else:
if form_data.model:
set_model_handler(form_data.model)

width, height = tuple(map(int, app.state.IMAGE_SIZE.split("x")))

data = {
"prompt": form_data.prompt,
"batch_size": form_data.n,
Expand All @@ -341,7 +435,7 @@ def generate_image(

res = r.json()

print(res)
log.debug(f"res: {res}")

images = []

Expand Down

0 comments on commit ac294a7

Please sign in to comment.