Commit ·
2eeb3a4
1
Parent(s): e029800
Set-up basic gradio template.
Browse files- .gitignore +5 -1
- app.py +54 -0
- config.py +45 -0
- logs/.gitkeep +0 -0
- main.py +0 -6
- pyproject.toml +15 -1
- static/style.css +1 -0
- uv.lock +0 -0
.gitignore
CHANGED
|
@@ -7,4 +7,8 @@ wheels/
|
|
| 7 |
*.egg-info
|
| 8 |
|
| 9 |
# Virtual environments
|
| 10 |
-
.venv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
*.egg-info
|
| 8 |
|
| 9 |
# Virtual environments
|
| 10 |
+
.venv
|
| 11 |
+
|
| 12 |
+
# application files
|
| 13 |
+
.gradio
|
| 14 |
+
*.log
|
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import structlog
|
| 5 |
+
|
| 6 |
+
import logging_config as _
|
| 7 |
+
|
| 8 |
+
# Create a logger instance
|
| 9 |
+
logger = structlog.get_logger(__name__)
|
| 10 |
+
|
| 11 |
+
with open("static/style.css", "r") as f:
|
| 12 |
+
css = f.read()
|
| 13 |
+
logger.info("Successfully loaded styles.")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def bot(message, history) -> list[Any]:
|
| 17 |
+
"""Generate bot response and history from message.
|
| 18 |
+
|
| 19 |
+
With multi-modal inputs text and each file is treated as separate message.
|
| 20 |
+
"""
|
| 21 |
+
logger.info("This is the history", history=history)
|
| 22 |
+
|
| 23 |
+
# enable message edit
|
| 24 |
+
if isinstance(message, str):
|
| 25 |
+
message = {"text": message}
|
| 26 |
+
|
| 27 |
+
# create text response
|
| 28 |
+
response = []
|
| 29 |
+
response.append("You wrote: '" + message.get("text") + "' and uploaded:")
|
| 30 |
+
|
| 31 |
+
# display files (exemplary)
|
| 32 |
+
if message.get("files"):
|
| 33 |
+
for file in message.get("files"):
|
| 34 |
+
response.append(gr.File(value=file))
|
| 35 |
+
|
| 36 |
+
logger.info(response=response)
|
| 37 |
+
return response
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
demo = gr.ChatInterface(
|
| 41 |
+
bot,
|
| 42 |
+
type="messages",
|
| 43 |
+
flagging_mode="manual",
|
| 44 |
+
editable=True,
|
| 45 |
+
flagging_options=["Like", "Dislike", "Spam", "Inappropriate", "Other"],
|
| 46 |
+
multimodal=True,
|
| 47 |
+
textbox=gr.MultimodalTextbox(file_count="multiple"),
|
| 48 |
+
title="DEval Prototype 1",
|
| 49 |
+
description="I am a playground to test Citation and the Basic set-up.",
|
| 50 |
+
css=css
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
demo.launch(share=False, server_name="0.0.0.0")
|
config.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic_settings import (
|
| 2 |
+
BaseSettings,
|
| 3 |
+
PydanticBaseSettingsSource,
|
| 4 |
+
SettingsConfigDict,
|
| 5 |
+
PyprojectTomlConfigSettingsSource,
|
| 6 |
+
)
|
| 7 |
+
from typing import Tuple, Type
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Settings(BaseSettings):
|
| 11 |
+
@classmethod
|
| 12 |
+
def settings_customise_sources(
|
| 13 |
+
cls,
|
| 14 |
+
settings_cls: Type[BaseSettings],
|
| 15 |
+
init_settings: PydanticBaseSettingsSource,
|
| 16 |
+
env_settings: PydanticBaseSettingsSource,
|
| 17 |
+
dotenv_settings: PydanticBaseSettingsSource,
|
| 18 |
+
file_secret_settings: PydanticBaseSettingsSource,
|
| 19 |
+
) -> Tuple[PydanticBaseSettingsSource, ...]:
|
| 20 |
+
return (
|
| 21 |
+
init_settings,
|
| 22 |
+
PyprojectTomlConfigSettingsSource(settings_cls),
|
| 23 |
+
env_settings,
|
| 24 |
+
dotenv_settings,
|
| 25 |
+
file_secret_settings,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class AppSettings(Settings):
|
| 30 |
+
# backend
|
| 31 |
+
llm_model: str
|
| 32 |
+
embedding_url: str
|
| 33 |
+
embedding_model: str
|
| 34 |
+
vector_db_url: str
|
| 35 |
+
vector_db_collection_name: str
|
| 36 |
+
|
| 37 |
+
# secrets
|
| 38 |
+
llm_api_key: str
|
| 39 |
+
|
| 40 |
+
model_config = SettingsConfigDict(
|
| 41 |
+
pyproject_toml_table_header=("tool", "app_config"),
|
| 42 |
+
env_file=".env",
|
| 43 |
+
env_file_encoding="utf-8",
|
| 44 |
+
extra="ignore",
|
| 45 |
+
)
|
logs/.gitkeep
ADDED
|
File without changes
|
main.py
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
def main():
|
| 2 |
-
print("Hello from deval-ai4kontextanalysen!")
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
if __name__ == "__main__":
|
| 6 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pyproject.toml
CHANGED
|
@@ -4,4 +4,18 @@ version = "0.1.0"
|
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.13"
|
| 7 |
-
dependencies = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
requires-python = ">=3.13"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"gradio>=5.33.0",
|
| 9 |
+
"pydantic>=2.11.5",
|
| 10 |
+
"pydantic-settings>=2.9.1",
|
| 11 |
+
"structlog>=25.4.0",
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
[tool.app_config]
|
| 16 |
+
# shared
|
| 17 |
+
llm_model = "gpt-4o"
|
| 18 |
+
embedding_model = "BAAI/bge-m3"
|
| 19 |
+
embedding_url = "http://tei:80"
|
| 20 |
+
vector_db_url = ":memory:"
|
| 21 |
+
vector_db_collection_name = "bgem3_store_multilingual"
|
static/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
footer { display: none !important; }
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|