Spaces:
Running
Running
Prepare Stylo Studio for Hugging Face Docker Space deployment
Browse files- .env.example +5 -0
- Dockerfile +30 -0
- README.md +9 -0
- backend/main.py +21 -0
- frontend/src/App.jsx +13 -6
- frontend/src/styles.css +9 -0
.env.example
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
OPENROUTER_API_KEY=your_openrouter_api_key_here
|
| 2 |
+
OPENROUTER_ENDPOINT=https://openrouter.ai/api/v1/chat/completions
|
| 3 |
+
OPENROUTER_SITE_URL=http://localhost:8000
|
| 4 |
+
OPENROUTER_APP_NAME=summarizer-uncertainty-app
|
| 5 |
+
SHOW_UNCERTAINTY=true
|
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:20-alpine AS frontend-build
|
| 2 |
+
|
| 3 |
+
WORKDIR /frontend
|
| 4 |
+
|
| 5 |
+
COPY frontend/package.json frontend/package-lock.json ./
|
| 6 |
+
RUN npm ci
|
| 7 |
+
|
| 8 |
+
COPY frontend ./
|
| 9 |
+
RUN npm run build
|
| 10 |
+
|
| 11 |
+
FROM python:3.13-slim
|
| 12 |
+
|
| 13 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 14 |
+
PYTHONUNBUFFERED=1 \
|
| 15 |
+
PIP_NO_CACHE_DIR=1 \
|
| 16 |
+
FRONTEND_DIST_DIR=/app/frontend_dist
|
| 17 |
+
|
| 18 |
+
WORKDIR /app
|
| 19 |
+
|
| 20 |
+
RUN pip install --no-cache-dir pipenv
|
| 21 |
+
|
| 22 |
+
COPY Pipfile Pipfile.lock /app/
|
| 23 |
+
RUN pipenv sync --system --deploy
|
| 24 |
+
|
| 25 |
+
COPY backend /app/backend
|
| 26 |
+
COPY --from=frontend-build /frontend/dist /app/frontend_dist
|
| 27 |
+
|
| 28 |
+
EXPOSE 7860
|
| 29 |
+
|
| 30 |
+
CMD ["uvicorn", "backend.main:backend", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# summarizer-uncertainty-app
|
| 2 |
|
| 3 |
A web application for uncertainty-aware editorial rewriting.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Stylo Studio
|
| 3 |
+
emoji: 📝
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
# summarizer-uncertainty-app
|
| 11 |
|
| 12 |
A web application for uncertainty-aware editorial rewriting.
|
backend/main.py
CHANGED
|
@@ -4,6 +4,7 @@ import logging
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
from datetime import datetime, timezone
|
|
|
|
| 7 |
from random import random
|
| 8 |
from typing import Any
|
| 9 |
from typing import Literal
|
|
@@ -12,6 +13,8 @@ import httpx
|
|
| 12 |
from dotenv import load_dotenv
|
| 13 |
from fastapi import FastAPI, HTTPException
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 15 |
from pydantic import BaseModel, Field
|
| 16 |
|
| 17 |
RewriteStyle = Literal["shorten", "professional", "informal"]
|
|
@@ -49,6 +52,7 @@ def _env_flag(name: str, default: bool) -> bool:
|
|
| 49 |
|
| 50 |
|
| 51 |
SHOW_UNCERTAINTY = _env_flag("SHOW_UNCERTAINTY", True)
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
class SummarizeRequest(BaseModel):
|
|
@@ -364,3 +368,20 @@ def submit_editorial_changes(payload: EditorialChangesRequest) -> EditorialChang
|
|
| 364 |
response.received_at,
|
| 365 |
)
|
| 366 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
+
from pathlib import Path
|
| 8 |
from random import random
|
| 9 |
from typing import Any
|
| 10 |
from typing import Literal
|
|
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
from fastapi import FastAPI, HTTPException
|
| 15 |
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
+
from fastapi.responses import FileResponse
|
| 17 |
+
from fastapi.staticfiles import StaticFiles
|
| 18 |
from pydantic import BaseModel, Field
|
| 19 |
|
| 20 |
RewriteStyle = Literal["shorten", "professional", "informal"]
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
SHOW_UNCERTAINTY = _env_flag("SHOW_UNCERTAINTY", True)
|
| 55 |
+
FRONTEND_DIST_DIR = Path(os.getenv("FRONTEND_DIST_DIR", "frontend/dist"))
|
| 56 |
|
| 57 |
|
| 58 |
class SummarizeRequest(BaseModel):
|
|
|
|
| 368 |
response.received_at,
|
| 369 |
)
|
| 370 |
return response
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
if FRONTEND_DIST_DIR.exists():
|
| 374 |
+
assets_dir = FRONTEND_DIST_DIR / "assets"
|
| 375 |
+
if assets_dir.exists():
|
| 376 |
+
backend.mount("/assets", StaticFiles(directory=assets_dir), name="assets")
|
| 377 |
+
|
| 378 |
+
@backend.get("/{full_path:path}", include_in_schema=False)
|
| 379 |
+
def serve_frontend(full_path: str) -> FileResponse:
|
| 380 |
+
"""Serve bundled frontend files when running as a single container."""
|
| 381 |
+
if full_path.startswith("api"):
|
| 382 |
+
raise HTTPException(status_code=404, detail="Not found")
|
| 383 |
+
|
| 384 |
+
requested = FRONTEND_DIST_DIR / full_path
|
| 385 |
+
if full_path and requested.exists() and requested.is_file():
|
| 386 |
+
return FileResponse(requested)
|
| 387 |
+
return FileResponse(FRONTEND_DIST_DIR / "index.html")
|
frontend/src/App.jsx
CHANGED
|
@@ -268,12 +268,19 @@ export function App() {
|
|
| 268 |
Click any sentence to edit it. High-uncertainty sentences are flagged automatically.
|
| 269 |
</p>
|
| 270 |
</div>
|
| 271 |
-
<aside
|
| 272 |
-
<
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
</aside>
|
| 278 |
</header>
|
| 279 |
|
|
|
|
| 268 |
Click any sentence to edit it. High-uncertainty sentences are flagged automatically.
|
| 269 |
</p>
|
| 270 |
</div>
|
| 271 |
+
<aside>
|
| 272 |
+
<a
|
| 273 |
+
className="foundation-badge"
|
| 274 |
+
href="https://humanfeedback.io"
|
| 275 |
+
target="_blank"
|
| 276 |
+
rel="noreferrer noopener"
|
| 277 |
+
>
|
| 278 |
+
<img src={hffLogo} alt="Human Feedback Foundation logo" className="foundation-logo" />
|
| 279 |
+
<div>
|
| 280 |
+
<p className="foundation-text">A project of the Human Feedback Foundation.</p>
|
| 281 |
+
<p className="foundation-text">We prototype open, human-centered futures for AI.</p>
|
| 282 |
+
</div>
|
| 283 |
+
</a>
|
| 284 |
</aside>
|
| 285 |
</header>
|
| 286 |
|
frontend/src/styles.css
CHANGED
|
@@ -86,10 +86,19 @@ body {
|
|
| 86 |
background: var(--paper);
|
| 87 |
border: 1px solid var(--line);
|
| 88 |
border-radius: 10px;
|
|
|
|
|
|
|
| 89 |
display: flex;
|
| 90 |
gap: 10px;
|
| 91 |
max-width: 360px;
|
| 92 |
padding: 8px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
.foundation-logo {
|
|
|
|
| 86 |
background: var(--paper);
|
| 87 |
border: 1px solid var(--line);
|
| 88 |
border-radius: 10px;
|
| 89 |
+
color: inherit;
|
| 90 |
+
cursor: pointer;
|
| 91 |
display: flex;
|
| 92 |
gap: 10px;
|
| 93 |
max-width: 360px;
|
| 94 |
padding: 8px;
|
| 95 |
+
text-decoration: none;
|
| 96 |
+
transition: transform 120ms ease, box-shadow 120ms ease;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.foundation-badge:hover {
|
| 100 |
+
box-shadow: 0 10px 24px rgba(10, 18, 28, 0.1);
|
| 101 |
+
transform: translateY(-1px);
|
| 102 |
}
|
| 103 |
|
| 104 |
.foundation-logo {
|