Spaces:
Sleeping
Sleeping
Deploy Bot commited on
Commit ·
7ba882a
1
Parent(s): 807821c
Deploy SciANN Material Identification app (Django + React + Vite)
Browse filesFiles changed (11)
- .gitignoreAdded+10
- DockerfileAdded+28
- backend/backend/settings.pyAdded+41
- backend/manage.pyAdded+11
- frontend/index.htmlAdded+12
- frontend/package.jsonAdded+19
- frontend/src/App.cssAdded+12
- frontend/src/App.jsxAdded+86
- frontend/src/main.jsxAdded+10
- frontend/vite.config.jsAdded+11
- requirements.txtAdded+9
12345678910node_modules/venv/__pycache__/*.pyc.envdist/frontend/dist/staticfiles/db.sqlite3*.log12345678910111213141516171819202122232425262728FROM python:3.9-slim
# Install system dependencies and Node.jsRUN apt-get update && apt-get install -y curl build-essential \ && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ && apt-get install -y nodejs && apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy Python requirements and installCOPY requirements.txt ./RUN pip install --no-cache-dir -r requirements.txt
# Copy projectCOPY . .
# Build frontendWORKDIR /app/frontendRUN npm install --no-audit --prefer-offlineRUN npm run build
# Collect static files for Django (Whitenoise)WORKDIR /appENV PORT=7860EXPOSE ${PORT}RUN python backend/manage.py collectstatic --noinput || true
CMD ["gunicorn", "backend.backend.wsgi:application", "--bind", "0.0.0.0:7860"]1234567891011121314151617181920212223242526272829303132333435363738394041import osfrom pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'change-me-before-prod'DEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDrk'DEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBeNoisDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDrk'DEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDEBDE]
ROOT_URLCONF = 'backend.urls'
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [BASE_DIR / '..' / 'frontend' / 'dist'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, },]
WSGI_APPLICATION = 'backend.wsgi.application'
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', }}
STATIC_URL = 'static/'STATIC_ROOT = os.path.join(BASE_DIR, '..', 'staticfiles')STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'CORS_ALLOW_ALL_ORIGINS = True1234567891011#!/usr/bin/env pythonimport osimport sys
if __name__ == '__main__': os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: raise ImportError("Couldn't import Django") from exc execute_from_command_line(sys.argv)123456789101112<!doctype html><html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>SciANN App</title> </head> <body> <div id="root"></div> <script type="module" src="/src/main.jsx"></script> </body></html>12345678910111213141516171819{ "name": "sciann-frontend", "version": "0.1.0", "private": true, "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview --port 5173" }, "dependencies": { "axios": "^1.4.0", "react": "^18.2.0", "react-dom": "^18.2.0" }, "devDependencies": { "@vitejs/plugin-react": "^4.0.0", "vite": "^5.0.0" }}123456789101112* { box-sizing: border-box; }body { font-family: Arial, sans-serif; background: #f3f4f6; margin: 0; padding: 20px; }.container { max-width: 800px; margin: 0 auto; }header { text-align: center; margin-bottom: 20px; }.card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }.input-group { margin-bottom: 12px; }.input-group label { display: block; font-weight: bold; margin-bottom: 6px; }input[type="number"] { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; }button { padding: 10px 14px; background: #2563eb; color: white; border: none; border-radius: 6px; cursor: pointer; }button[disabled] { opacity: 0.6; cursor: not-allowed; }.result { margin-top: 16px; }.error { color: #b91c1c; }1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { useState } from 'react'import axios from 'axios'import './App.css'
export default function App() { const [param1, setParam1] = useState('') const [param2, setParam2] = useState('') const [result, setResult] = useState(null) const [loading, setLoading] = useState(false) const [error, setError] = useState('')
const handleSubmit = async (e) => { e.preventDefault() setLoading(true) setError('') setResult(null)
try { const response = await axios.post('/api/predict/', { param1: parseFloat(param1), param2: parseFloat(param2) }) setResult(response.data) } catch (err) { setError('Error during material identification.') console.error(err) } finally { setLoading(false) } }
return ( <div className="container"> <header> <h1>Material Identification: Talc</h1> <p>Based on SciANN and Hugging Face</p> </header>
<div className="card"> <h2>Input Parameters</h2> <form onSubmit={handleSubmit}> <div className="input-group"> <label>Parameter 1 (Stress):</label> <input type="number" step="0.01" value={param1} onChange={(e) => setParam1(e.target.value)} required /> </div> <div className="input-group"> <label>Parameter 2 (Strain):</label> <input type="number" step="0.01" value={param2} onChange={(e) => setParam2(e.target.value)} required /> </div> <button type="submit" disabled={loading}> {loading ? 'Analyzing...' : 'Identify Material'} </button> </form>
{error && <p className="error">{error}</p>}
{result && ( <div className="result"> <h3>Result</h3> <p><strong>Material:</strong> {result.material}</p> <p><strong>Confidence:</strong> {(result.confidence * 100).toFixed(2)}%</p> {result.properties && ( <div> <h4>Predicted Properties</h4> <p>Stress: {result.properties.stress.toFixed(4)}</p> <p>Strain: {result.properties.strain.toFixed(4)}</p> </div> )} </div> )} </div> </div> )}12345678910import React from 'react'import { createRoot } from 'react-dom/client'import App from './App'import './App.css'
createRoot(document.getElementById('root')).render( <React.StrictMode> <App /> </React.StrictMode>)1234567891011import { defineConfig } from 'vite'import react from '@vitejs/plugin-react'
export default defineConfig({ plugins: [react()], base: './', build: { outDir: 'dist', emptyOutDir: true, },})123456789Django>=4.2djangorestframeworkdjango-cors-headerswhitenoisescikit-learnsciannnumpypandasgunicorn.gitignoreAdded+10
DockerfileAdded+28
backend/backend/settings.pyAdded+41
backend/manage.pyAdded+11
frontend/index.htmlAdded+12
frontend/package.jsonAdded+19
frontend/src/App.cssAdded+12
frontend/src/App.jsxAdded+86
frontend/src/main.jsxAdded+10
frontend/vite.config.jsAdded+11
requirements.txtAdded+9