Commit bb9d4ab2 authored by ZeinabRm13's avatar ZeinabRm13

Add chat

parent 74097a42
File added
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title> <title>Chart Analyzer</title>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"axios": "^1.11.0", "axios": "^1.11.0",
"mini.css": "^3.0.1",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-router-dom": "^7.7.1" "react-router-dom": "^7.7.1"
...@@ -2952,6 +2953,12 @@ ...@@ -2952,6 +2953,12 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/mini.css": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/mini.css/-/mini.css-3.0.1.tgz",
"integrity": "sha512-FmuuBL0wuyDO1UA66TkAo8w2RxxuHmNPaUqUHcYlHtM9CJkrscQaNAJ/ParEahYFwtZOSgfEA7flbMoSPkzrPA==",
"license": "MIT"
},
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "3.1.2", "version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",
"axios": "^1.11.0", "axios": "^1.11.0",
"mini.css": "^3.0.1",
"react": "^19.1.0", "react": "^19.1.0",
"react-dom": "^19.1.0", "react-dom": "^19.1.0",
"react-router-dom": "^7.7.1" "react-router-dom": "^7.7.1"
......
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
\ No newline at end of file
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
import { useState } from 'react' import { RouterProvider } from 'react-router-dom';
import reactLogo from './assets/react.svg' import { router } from './Routes/Routes';
import viteLogo from '/vite.svg'
import './App.css'
function App() { function App() {
const [count, setCount] = useState(0) return <RouterProvider router={router} />;
return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
} }
export default App export default App;
\ No newline at end of file
import { createBrowserRouter } from 'react-router-dom';
import { Login } from '../pages/Auth/Login';
import { Register } from '../pages/Auth/Register';
import { AskQuestion } from '../pages/Charts/AskQuestion';
import { AnalyzeChart } from '../pages/Charts/AnalyzeChart';
import { Home } from '../pages/Home';
import { ChatInterface } from '../components/ChatInteface';
export const router = createBrowserRouter([
{
path: '/',
element: <Home />,
},
{
path: '/auth/login',
element: <Login />,
},
{
path: '/auth/register',
element: <Register />,
},
{
path: '/charts/ask',
element: <AskQuestion />,
},
{
path: '/charts/analyze',
element: <AnalyzeChart />,
},
{
path: '/charts/chat',
element: <ChatInterface />,
},
]);
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
\ No newline at end of file
import { useRef, useState } from 'react';
export const ChatInput = ({
onSendMessage,
onUploadImage,
isProcessing,
}: {
onSendMessage: (text: string) => void;
onUploadImage: (file: File) => void;
isProcessing: boolean;
}) => {
const [message, setMessage] = useState('');
const fileInputRef = useRef<HTMLInputElement>(null);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (message.trim() && !isProcessing) {
onSendMessage(message);
setMessage('');
}
};
const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
onUploadImage(e.target.files[0]);
}
};
return (
<form onSubmit={handleSubmit} className="chat-input-container">
<button
type="button"
onClick={() => fileInputRef.current?.click()}
className="upload-button"
disabled={isProcessing}
>
📎
</button>
<input
type="file"
ref={fileInputRef}
onChange={handleImageUpload}
accept="image/*"
className="file-input"
/>
<input
type="text"
value={message}
onChange={(e) => setMessage(e.target.value)}
placeholder="Ask about the chart..."
className="message-input"
disabled={isProcessing}
/>
<button type="submit" className="send-button" disabled={!message.trim() || isProcessing}>
{isProcessing ? '⏳' : '➤'}
</button>
</form>
);
};
\ No newline at end of file
"use client"
import { useState, useRef, useEffect } from "react"
import { ChatMessage } from "./ChatMessage"
import { ChatInput } from "./ChatInput"
import type { MessageType } from "../types"
import { chartService } from "../services/api"
import "../styles/chat.css"
export const ChatInterface = () => {
const [messages, setMessages] = useState<MessageType[]>([])
const [isProcessing, setIsProcessing] = useState(false)
const messagesEndRef = useRef<HTMLDivElement>(null)
// Auto-scroll to bottom
useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" })
}, [messages])
const handleSendMessage = async (text: string) => {
const userMessage: MessageType = {
id: Date.now().toString(),
content: text,
sender: "user",
type: "text",
timestamp: new Date(),
}
setMessages((prev) => [...prev, userMessage])
setIsProcessing(true)
try {
// Find the last uploaded image in the chat
const lastImageMessage = [...messages].reverse().find((msg) => msg.type === "image" && msg.sender === "user")
if (!lastImageMessage) {
setMessages((prev) => [
...prev,
{
id: Date.now().toString(),
content: "Please upload a chart image first before asking questions.",
sender: "bot",
type: "text",
timestamp: new Date(),
},
])
return
}
const formData = new FormData()
// You might need to convert the image URL back to a file if needed
// Or modify your backend to accept image URLs
formData.append("question", text)
formData.append("image", await fetch(lastImageMessage.content).then((r) => r.blob()))
const response = await chartService.AskQuestion(formData)
const botMessage: MessageType = {
id: Date.now().toString(),
content: response.data.answer || response.data,
sender: "bot",
type: "text",
timestamp: new Date(),
}
setMessages((prev) => [...prev, botMessage])
} catch (error) {
const errorMessage: MessageType = {
id: Date.now().toString(),
content: "Sorry, I encountered an error processing your question. Please try again.",
sender: "bot",
type: "text",
timestamp: new Date(),
}
setMessages((prev) => [...prev, errorMessage])
} finally {
setIsProcessing(false)
}
}
const handleUploadImage = (file: File) => {
const reader = new FileReader()
reader.onloadend = () => {
const imageMessage: MessageType = {
id: Date.now().toString(),
content: reader.result as string,
sender: "user",
type: "image",
timestamp: new Date(),
}
setMessages((prev) => [...prev, imageMessage])
}
reader.readAsDataURL(file)
}
return (
<div className="chat-interface">
<div className="chat-container">
<div className="chat-header">
<h1>Chart Chat Assistant</h1>
<p>Upload a chart and ask questions about it</p>
</div>
<div className="chat-messages">
{messages.length === 0 ? (
<div className="chat-empty-state">
<div className="empty-icon">💬</div>
<h3>Start a conversation</h3>
<p>Upload a chart image and ask me anything about it!</p>
</div>
) : (
messages.map((message) => <ChatMessage key={message.id} message={message} />)
)}
<div ref={messagesEndRef} />
</div>
<ChatInput onSendMessage={handleSendMessage} onUploadImage={handleUploadImage} isProcessing={isProcessing} />
</div>
</div>
)
}
import type { MessageType } from '../types';
export const ChatMessage = ({ message }: { message: MessageType }) => {
return (
<div className={`chat-message ${message.sender}`}>
<div className="message-content">
{message.type === 'text' && (
<p>{message.content}</p>
)}
{message.type === 'image' && (
<img src={message.content} alt="Uploaded chart" className="chat-image" />
)}
</div>
<div className="message-time">
{new Date(message.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
</div>
</div>
);
};
\ No newline at end of file
/* CSS Reset and Global Styles */
*,
*::before,
*::after {
box-sizing: border-box;
}
* {
margin: 0;
padding: 0;
}
:root { :root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif; /* Color Palette */
line-height: 1.5; --primary-50: #eff6ff;
font-weight: 400; --primary-100: #dbeafe;
--primary-200: #bfdbfe;
--primary-300: #93c5fd;
--primary-400: #60a5fa;
--primary-500: #3b82f6;
--primary-600: #2563eb;
--primary-700: #1d4ed8;
--primary-800: #1e40af;
--primary-900: #1e3a8a;
--gray-50: #f9fafb;
--gray-100: #f3f4f6;
--gray-200: #e5e7eb;
--gray-300: #d1d5db;
--gray-400: #9ca3af;
--gray-500: #6b7280;
--gray-600: #4b5563;
--gray-700: #374151;
--gray-800: #1f2937;
--gray-900: #111827;
color-scheme: light dark; --success-500: #10b981;
color: rgba(255, 255, 255, 0.87); --success-600: #059669;
background-color: #242424; --error-500: #ef4444;
--error-600: #dc2626;
--warning-500: #f59e0b;
--warning-600: #d97706;
font-synthesis: none; /* Typography */
text-rendering: optimizeLegibility; --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
--font-family-mono: "SF Mono", Monaco, Inconsolata, "Roboto Mono", Consolas, "Courier New", monospace;
/* Spacing */
--space-1: 0.25rem;
--space-2: 0.5rem;
--space-3: 0.75rem;
--space-4: 1rem;
--space-5: 1.25rem;
--space-6: 1.5rem;
--space-8: 2rem;
--space-10: 2.5rem;
--space-12: 3rem;
--space-16: 4rem;
--space-20: 5rem;
/* Border Radius */
--radius-sm: 0.375rem;
--radius-md: 0.5rem;
--radius-lg: 0.75rem;
--radius-xl: 1rem;
--radius-2xl: 1.5rem;
/* Shadows */
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
/* Transitions */
--transition-fast: 150ms ease;
--transition-normal: 250ms ease;
--transition-slow: 350ms ease;
}
html {
line-height: 1.5;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
a { body {
font-weight: 500; font-family: var(--font-family-sans);
color: #646cff; background-color: var(--gray-50);
text-decoration: inherit; color: var(--gray-900);
} font-size: 1rem;
a:hover { line-height: 1.6;
color: #535bf2;
} }
body { img,
margin: 0; picture,
display: flex; video,
place-items: center; canvas,
min-width: 320px; svg {
min-height: 100vh; display: block;
max-width: 100%;
} }
h1 { input,
font-size: 3.2em; button,
line-height: 1.1; textarea,
select {
font: inherit;
} }
button { button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer; cursor: pointer;
transition: border-color 0.25s;
} }
button:hover {
border-color: #646cff; a {
color: inherit;
text-decoration: none;
} }
button:focus,
button:focus-visible { /* Utility Classes */
outline: 4px auto -webkit-focus-ring-color; .container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 0 var(--space-4);
} }
@media (prefers-color-scheme: light) { @media (min-width: 640px) {
:root { .container {
color: #213547; padding: 0 var(--space-6);
background-color: #ffffff;
}
a:hover {
color: #747bff;
} }
button { }
background-color: #f9f9f9;
@media (min-width: 1024px) {
.container {
padding: 0 var(--space-8);
} }
} }
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
"use client"
import type React from "react"
import { useState } from "react"
import { authService } from "../../services/api"
import { useNavigate, Link } from "react-router-dom"
import "../../styles/auth.css"
export const Login = () => {
const [formData, setFormData] = useState({
username: "",
password: "",
})
const [error, setError] = useState("")
const [isLoading, setIsLoading] = useState(false)
const navigate = useNavigate()
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setIsLoading(true)
try {
setError("")
const response = await authService.login(formData)
localStorage.setItem("token", response.data.token)
localStorage.setItem("username", formData.username)
navigate("/")
} catch (err: any) {
setError(err.response?.data?.detail || "Invalid credentials")
} finally {
setIsLoading(false)
}
}
return (
<div className="auth-container">
<div className="auth-card">
<div className="auth-header">
<h2>Welcome Back</h2>
<p>Sign in to your account to continue</p>
</div>
<div className="auth-content">
{error && <div className="error-message">{error}</div>}
<form onSubmit={handleSubmit} className="auth-form">
<div className="form-group">
<label htmlFor="username">Username</label>
<input
id="username"
type="text"
value={formData.username}
onChange={(e) => setFormData({ ...formData, username: e.target.value })}
required
placeholder="Enter your username"
/>
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input
id="password"
type="password"
value={formData.password}
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
required
placeholder="Enter your password"
/>
</div>
<button type="submit" className="submit-button" disabled={isLoading}>
{isLoading ? "Signing in..." : "Sign In"}
</button>
</form>
</div>
<div className="auth-footer">
<p>Don't have an account?</p>
<Link to="/auth/register">Create one here</Link>
</div>
</div>
</div>
)
}
"use client"
import type React from "react"
import { useState } from "react"
import { authService } from "../../services/api"
import { useNavigate } from "react-router-dom"
import { Link } from "react-router-dom"
import "../../styles/auth.css"
export const Register = () => {
const [formData, setFormData] = useState({
username: "",
email: "",
password: "",
confirmPassword: "",
})
const [error, setError] = useState("")
const [success, setSuccess] = useState(false)
const navigate = useNavigate()
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
// Basic validation
if (formData.password !== formData.confirmPassword) {
setError("Passwords do not match")
return
}
try {
setError("")
await authService.register({
username: formData.username,
email: formData.email,
password: formData.password,
})
setSuccess(true)
// Auto-redirect after 2 seconds
setTimeout(() => navigate("/auth/login"), 2000)
} catch (err: any) {
setError(err.response?.data?.detail || "Registration failed")
}
}
if (success) {
return (
<div className="success-message">
<div className="success-icon"></div>
<h2>Registration Successful!</h2>
<p>You will be redirected to login page shortly...</p>
</div>
)
}
return (
<div className="auth-container">
<div className="auth-card">
<div className="auth-header">
<h2>Create Account</h2>
<p>Join us to start analyzing your charts</p>
</div>
<div className="auth-content">
{error && <div className="error-message">{error}</div>}
<form onSubmit={handleSubmit} className="auth-form">
<div className="form-group">
<label htmlFor="username">Username</label>
<input
id="username"
type="text"
value={formData.username}
onChange={(e) => setFormData({ ...formData, username: e.target.value })}
required
minLength={3}
placeholder="Enter your username"
/>
</div>
<div className="form-group">
<label htmlFor="email">Email</label>
<input
id="email"
type="email"
value={formData.email}
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
required
placeholder="Enter your email"
/>
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input
id="password"
type="password"
value={formData.password}
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
required
minLength={6}
placeholder="Enter your password"
/>
</div>
<div className="form-group">
<label htmlFor="confirmPassword">Confirm Password</label>
<input
id="confirmPassword"
type="password"
value={formData.confirmPassword}
onChange={(e) => setFormData({ ...formData, confirmPassword: e.target.value })}
required
minLength={6}
placeholder="Confirm your password"
/>
</div>
<button type="submit" className="submit-button">
Create Account
</button>
</form>
</div>
<div className="auth-footer">
<p>Already have an account?</p>
<Link to="/auth/login">Sign in here</Link>
</div>
</div>
</div>
)
}
"use client"
import type React from "react"
import { useState, useRef } from "react"
import { chartService } from "../../services/api"
import "../../styles/charts.css"
export const AnalyzeChart = () => {
const [image, setImage] = useState<File | null>(null)
const [preview, setPreview] = useState<string | null>(null)
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState("")
const [analysisResult, setAnalysisResult] = useState("")
const fileInputRef = useRef<HTMLInputElement>(null)
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
const file = e.target.files[0]
setImage(file)
setAnalysisResult("") // Clear previous result when new image is selected
// Create preview URL
const reader = new FileReader()
reader.onloadend = () => {
setPreview(reader.result as string)
}
reader.readAsDataURL(file)
}
}
const handleAnalyze = async (e: React.FormEvent) => {
e.preventDefault()
if (!image) {
setError("Please upload an image first")
return
}
try {
setIsLoading(true)
setError("")
setAnalysisResult("")
// Create FormData as your API expects
const formData = new FormData()
formData.append("image", image) // Matches your -F 'image=@file.png'
const response = await chartService.analyzeChart(formData)
setAnalysisResult(response.data.analysis || response.data.result || "Analysis complete")
} catch (err: any) {
setError(err.response?.data?.detail || "Analysis failed")
console.error("Error analyzing chart:", err)
} finally {
setIsLoading(false)
}
}
const triggerFileInput = () => {
fileInputRef.current?.click()
}
return (
<div className="analyze-chart-container">
<div className="analyze-content">
<h1 className="analyze-title">Chart Analysis</h1>
<div className="upload-section">
<input type="file" ref={fileInputRef} onChange={handleImageChange} accept="image/*" className="file-input" />
{preview ? (
<div className="image-preview-container">
<img src={preview || "/placeholder.svg"} alt="Chart preview" className="image-preview" />
<button onClick={triggerFileInput} className="change-image-button">
Change Image
</button>
</div>
) : (
<div className="upload-area" onClick={triggerFileInput}>
<div className="upload-icon">📊</div>
<p>Click to upload chart image</p>
<p className="upload-hint">Supports PNG, JPG, SVG files</p>
</div>
)}
</div>
{error && <div className="error-message">{error}</div>}
<div className="action-section">
<button onClick={handleAnalyze} className="analyze-button" disabled={isLoading || !image}>
{isLoading ? (
<>
<span className="spinner"></span>
Analyzing Chart...
</>
) : (
<>
<span>🔍</span>
Analyze Chart
</>
)}
</button>
</div>
{analysisResult && (
<div className="result-section">
<h3 className="result-title">Analysis Result</h3>
<div className="result-content">{analysisResult}</div>
</div>
)}
</div>
</div>
)
}
"use client"
import type React from "react"
import { useState, useRef } from "react"
import { chartService } from "../../services/api"
import "../../styles/charts.css"
export const AskQuestion = () => {
const [image, setImage] = useState<File | null>(null)
const [preview, setPreview] = useState<string | null>(null)
const [question, setQuestion] = useState("")
const [answer, setAnswer] = useState("")
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState("")
const fileInputRef = useRef<HTMLInputElement>(null)
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files[0]) {
const file = e.target.files[0]
setImage(file)
// Create preview URL
const reader = new FileReader()
reader.onloadend = () => {
setPreview(reader.result as string)
}
reader.readAsDataURL(file)
}
}
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
if (!image) {
setError("Please upload an image first")
return
}
if (!question.trim()) {
setError("Please enter your question")
return
}
try {
setIsLoading(true)
setError("")
setAnswer("")
// Create FormData matching your curl example exactly
const formData = new FormData()
formData.append("image", image) // Matches your -F 'image=@...'
formData.append("question", question) // Matches your -F 'question=...'
const response = await chartService.AskQuestion(formData)
setAnswer(response.data.answer) // Adjust based on your API response structure
} catch (err: any) {
setError(err.response?.data?.detail || "Analysis failed")
console.error("Error analyzing chart:", err)
} finally {
setIsLoading(false)
}
}
const triggerFileInput = () => {
fileInputRef.current?.click()
}
return (
<div className="analyze-chart-container">
<div className="analyze-content">
<h1 className="analyze-title">Ask About Your Chart</h1>
<div className="upload-section">
<input type="file" ref={fileInputRef} onChange={handleImageChange} accept="image/*" className="file-input" />
{preview ? (
<div className="image-preview-container">
<img src={preview || "/placeholder.svg"} alt="Chart preview" className="image-preview" />
<button onClick={triggerFileInput} className="change-image-button">
Change Image
</button>
</div>
) : (
<div className="upload-area" onClick={triggerFileInput}>
<div className="upload-icon">📊</div>
<p>Click to upload chart image</p>
<p className="upload-hint">Supports PNG, JPG, SVG files</p>
</div>
)}
</div>
<form onSubmit={handleSubmit} className="analysis-form">
<div className="form-group">
<label htmlFor="question" className="question-label">
What would you like to know about this chart?
</label>
<textarea
id="question"
value={question}
onChange={(e) => setQuestion(e.target.value)}
rows={4}
placeholder="Example: What is the highest value shown in this chart? What trends can you identify?"
disabled={isLoading}
className="question-input"
/>
</div>
{error && <div className="error-message">{error}</div>}
<div className="button-group">
<button type="submit" className="analyze-button" disabled={isLoading || !image || !question.trim()}>
{isLoading ? (
<>
<span className="spinner"></span>
Getting Answer...
</>
) : (
<>
<span></span>
Ask Question
</>
)}
</button>
</div>
</form>
{answer && (
<div className="answer-section">
<h3 className="answer-title">Answer</h3>
<div className="answer-content">
{typeof answer === "string" ? answer : JSON.stringify(answer, null, 2)}
</div>
</div>
)}
</div>
</div>
)
}
import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { appService } from '../services/api';
// import { authService } from '../services/api';
import '../styles/home.css';
export const Home = () => {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [serverStatus, setServerStatus] = useState<'loading' | 'online' | 'offline'>('loading');
const [userData, setUserData] = useState<{ username: string } | null>(null);
const [featureCards] = useState([
{
title: "Chart Analysis",
description: "Upload and analyze your charts with our powerful tools",
path: "/charts/analyze",
},
{
title: "Ask Questions",
description: "Get insights about your data by asking natural language questions",
path: "/charts/ask",
},
]);
useEffect(() => {
// Check if user is authenticated
const token = localStorage.getItem('token');
setIsAuthenticated(!!token);
// Fetch server status
const checkServerStatus = async () => {
try {
await appService.getRoot();
setServerStatus('online');
} catch (error) {
setServerStatus('offline');
}
};
checkServerStatus();
// If authenticated, fetch user data
if (token) {
const fetchUserData = async () => {
try {
// Assuming you have an endpoint to get current user
// const response = await authService.getCurrentUser();
// setUserData(response.data);
// For now, just get username from token or local storage
setUserData({ username: localStorage.getItem('username') || 'User' });
} catch (error) {
console.error('Failed to fetch user data:', error);
}
};
fetchUserData();
}
}, []);
const handleLogout = async () => {
try {
// Optional: Call logout endpoint if you have one
// await authService.logout();
localStorage.removeItem('token');
localStorage.removeItem('username');
setIsAuthenticated(false);
setUserData(null);
} catch (error) {
console.error('Logout failed:', error);
}
};
return (
<div className="home-container">
<header className="home-header">
<div className="server-status">
Server Status:
<span className={`status-indicator ${serverStatus}`}>
{serverStatus.toUpperCase()}
</span>
</div>
<nav className="auth-nav">
{isAuthenticated ? (
<div className="user-section">
<span>Welcome, {userData?.username}</span>
<button onClick={handleLogout} className="logout-button">
Logout
</button>
</div>
) : (
<>
<Link to="/auth/login" className="auth-link">
Login
</Link>
<Link to="/auth/register" className="auth-link">
Register
</Link>
</>
)}
</nav>
</header>
<main className="home-main">
<section className="hero-section">
<h1>Data Visualization & Analysis Platform</h1>
<p>
Transform your data into insights with our powerful chart analysis tools
and AI-powered question answering system.
</p>
</section>
<section className="features-section">
<h2>Key Features</h2>
<div className="feature-cards">
{featureCards.map((feature, index) => (
<div key={index} className="feature-card">
<h3>{feature.title}</h3>
<p>{feature.description}</p>
<Link to={feature.path} className="feature-link">
Try it out →
</Link>
</div>
))}
</div>
</section>
{!isAuthenticated && (
<section className="cta-section">
<h2>Ready to get started?</h2>
<div className="cta-buttons">
<Link to="/auth/register" className="cta-button primary">
Create Account
</Link>
<Link to="/auth/login" className="cta-button secondary">
Login
</Link>
</div>
</section>
)}
</main>
<footer className="home-footer">
<p>© {new Date().getFullYear()} Data Analysis Platform. All rights reserved.</p>
</footer>
</div>
);
};
\ No newline at end of file
import { useState } from 'react';
import { authService } from '../../services/api';
import { useNavigate } from 'react-router-dom';
export const Login = () => {
const [formData, setFormData] = useState({
username: '',
password: '',
});
const [error, setError] = useState('');
const navigate = useNavigate();
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
const response = await authService.login(formData);
localStorage.setItem('token', response.data.token);
navigate('/charts');
} catch (err) {
setError('Invalid credentials');
}
};
return (
<div>
<h2>Login</h2>
{error && <p style={{ color: 'red' }}>{error}</p>}
<form onSubmit={handleSubmit}>
<input
type="text"
placeholder="Username"
value={formData.username}
onChange={(e) => setFormData({...formData, username: e.target.value})}
/>
<input
type="password"
placeholder="Password"
value={formData.password}
onChange={(e) => setFormData({...formData, password: e.target.value})}
/>
<button type="submit">Login</button>
</form>
</div>
);
};
\ No newline at end of file
import axios from 'axios'; import axios from 'axios';
const api = axios.create({ const api = axios.create({
baseURL: 'http://localhost:8000', baseURL: 'http://localhost:8000', // Your FastAPI URL
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'application/json',
}, },
withCredentials: true, // If you need to send cookies
}); });
export default api;
// Auth services // Auth services
export const authService = { export const authService = {
register: (data: { username: string; password: string; email: string }) => register: (data: { username: string; password: string; email: string }) =>
...@@ -17,10 +24,20 @@ export const authService = { ...@@ -17,10 +24,20 @@ export const authService = {
// Chart services // Chart services
export const chartService = { export const chartService = {
askAboutChart: (data: { chartId: string; question: string }) => AskQuestion: (formData: FormData) =>
api.post('/charts/ask', data), api.post('/charts/ask', formData, {
analyzeChart: (data: { chartData: any }) => headers: {
api.post('/charts/analyze', data), 'Content-Type': 'multipart/form-data',
'accept': 'application/json',
},
}),
analyzeChart: (formData: FormData) =>
api.post('/charts/analyze', formData, {
headers: {
'accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
}),
}; };
// General services // General services
......
.auth-container {
max-width: 400px;
margin: 2rem auto;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.auth-form {
display: flex;
flex-direction: column;
gap: 1rem;
}
.form-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.form-group label {
font-weight: 500;
}
.form-group input {
padding: 0.5rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.submit-button {
padding: 0.75rem;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
margin-top: 1rem;
}
.submit-button:hover {
background-color: #45a049;
}
.error-message {
color: #f44336;
padding: 0.5rem;
background-color: #ffebee;
border-radius: 4px;
margin-bottom: 1rem;
}
.success-message {
color: #4CAF50;
text-align: center;
margin-top: 2rem;
}
.auth-footer {
margin-top: 1rem;
text-align: center;
}
.auth-footer a {
color: #4CAF50;
text-decoration: none;
}
.auth-footer a:hover {
text-decoration: underline;
}
\ No newline at end of file
/* charts.css */
.analyze-chart-container {
max-width: 800px;
margin: 2rem auto;
padding: 2rem;
background-color: #fff;
border-radius: 12px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.analyze-title {
text-align: center;
color: #2c3e50;
margin-bottom: 2rem;
font-size: 1.8rem;
}
.upload-section {
margin-bottom: 2rem;
border-radius: 10px;
overflow: hidden;
}
.file-input {
display: none;
}
.upload-area {
border: 2px dashed #bdc3c7;
border-radius: 10px;
padding: 3rem 2rem;
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
background-color: #f8f9fa;
}
.upload-area:hover {
border-color: #3498db;
background-color: #e9f7fe;
}
.upload-icon {
font-size: 3.5rem;
color: #7f8c8d;
margin-bottom: 1rem;
line-height: 1;
}
.upload-hint {
color: #95a5a6;
font-size: 0.9rem;
margin-top: 0.5rem;
}
.image-preview-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
}
.image-preview {
max-width: 100%;
max-height: 400px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border: 1px solid #eee;
}
.change-image-button {
background-color: #f8f9fa;
border: 1px solid #bdc3c7;
padding: 0.6rem 1.2rem;
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
font-size: 0.9rem;
}
.change-image-button:hover {
background-color: #e9ecef;
border-color: #95a5a6;
}
.action-section {
display: flex;
justify-content: center;
margin: 2rem 0;
}
.analyze-button {
padding: 0.8rem 2rem;
background-color: #3498db;
color: white;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s ease;
display: flex;
align-items: center;
gap: 0.5rem;
}
.analyze-button:hover:not(:disabled) {
background-color: #2980b9;
}
.analyze-button:disabled {
background-color: #bdc3c7;
cursor: not-allowed;
}
.spinner {
width: 1rem;
height: 1rem;
border: 2px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: white;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.error-message {
color: #e74c3c;
padding: 1rem;
background-color: #fadbd8;
border-radius: 8px;
margin: 1.5rem 0;
text-align: center;
border-left: 4px solid #e74c3c;
}
.result-section {
margin-top: 2rem;
padding: 1.5rem;
background-color: #f8f9fa;
border-radius: 8px;
border-left: 4px solid #2ecc71;
}
.result-title {
color: #2c3e50;
margin-bottom: 1rem;
font-size: 1.3rem;
}
.result-content {
white-space: pre-wrap;
line-height: 1.6;
color: #34495e;
}
\ No newline at end of file
/* chat.css */
.chat-interface {
min-height: 100vh;
display: flex;
flex-direction: column;
background: linear-gradient(135deg, var(--gray-50) 0%, var(--primary-50) 100%);
padding: var(--space-4);
}
.chat-container {
max-width: 900px;
margin: 0 auto;
width: 100%;
height: calc(100vh - 2rem);
display: flex;
flex-direction: column;
background: rgb(20, 7, 51);
border-radius: var(--radius-2xl);
box-shadow: var(--shadow-xl);
border: 1px solid var(--gray-200);
overflow: hidden;
}
.chat-header {
background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
color: white;
padding: var(--space-6);
text-align: center;
border-bottom: 1px solid var(--primary-400);
}
.chat-header h1 {
font-size: 1.5rem;
font-weight: 700;
margin-bottom: var(--space-2);
}
.chat-header p {
opacity: 0.9;
font-size: 0.875rem;
}
.chat-messages {
flex: 1;
padding: var(--space-6);
overflow-y: auto;
display: flex;
flex-direction: column;
gap: var(--space-4);
background: linear-gradient(135deg, var(--gray-50), var(--primary-50));
scroll-behavior: smooth;
}
.chat-message {
max-width: 85%;
padding: var(--space-4) var(--space-5);
border-radius: var(--radius-xl);
line-height: 1.6;
font-size: 0.95rem;
position: relative;
box-shadow: var(--shadow-md);
animation: messageSlide 0.3s ease-out;
}
@keyframes messageSlide {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.chat-message.user {
align-self: flex-end;
background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
color: white;
border-bottom-right-radius: var(--radius-md);
border: 1px solid var(--primary-400);
}
.chat-message.bot {
align-self: flex-start;
background: white;
color: var(--gray-800);
border: 1px solid var(--gray-200);
border-bottom-left-radius: var(--radius-md);
border-left: 4px solid var(--primary-500);
}
.message-content {
word-wrap: break-word;
margin-bottom: var(--space-2);
}
.message-content p {
margin: 0;
}
.chat-image {
max-width: 100%;
max-height: 300px;
border-radius: var(--radius-lg);
margin-top: var(--space-3);
box-shadow: var(--shadow-md);
border: 1px solid var(--gray-200);
transition: transform var(--transition-normal);
}
.chat-image:hover {
transform: scale(1.02);
}
.message-time {
font-size: 0.75rem;
opacity: 0.7;
text-align: right;
font-weight: 500;
}
.chat-input-container {
display: flex;
align-items: flex-end;
padding: var(--space-6);
background: white;
border-top: 1px solid var(--gray-200);
gap: var(--space-3);
}
.message-input {
flex: 1;
padding: var(--space-4) var(--space-5);
border: 2px solid var(--gray-200);
border-radius: var(--radius-xl);
outline: none;
font-size: 1rem;
line-height: 1.5;
transition: all var(--transition-fast);
background: var(--gray-50);
resize: none;
min-height: 44px;
max-height: 120px;
}
.message-input:focus {
border-color: var(--primary-500);
background: white;
box-shadow: 0 0 0 3px var(--primary-100);
}
.message-input::placeholder {
color: var(--gray-400);
}
.upload-button,
.send-button {
width: 48px;
height: 48px;
border-radius: 50%;
border: none;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.25rem;
transition: all var(--transition-fast);
flex-shrink: 0;
position: relative;
overflow: hidden;
}
.upload-button {
background: var(--gray-100);
color: var(--gray-600);
border: 2px solid var(--gray-200);
}
.upload-button::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(107, 114, 128, 0.1), transparent);
transition: left 0.3s;
}
.upload-button:hover {
background: var(--gray-200);
border-color: var(--gray-300);
transform: translateY(-1px);
}
.upload-button:hover::before {
left: 100%;
}
.send-button {
background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
color: white;
box-shadow: var(--shadow-md);
}
.send-button::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transition: left 0.3s;
}
.send-button:hover:not(:disabled) {
background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
transform: translateY(-2px);
box-shadow: var(--shadow-lg);
}
.send-button:hover:not(:disabled)::before {
left: 100%;
}
.send-button:disabled {
opacity: 0.6;
cursor: not-allowed;
background: var(--gray-300);
transform: none;
box-shadow: var(--shadow-sm);
}
/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
width: 8px;
}
.chat-messages::-webkit-scrollbar-track {
background: var(--gray-100);
border-radius: var(--radius-md);
}
.chat-messages::-webkit-scrollbar-thumb {
background: var(--gray-300);
border-radius: var(--radius-md);
transition: background var(--transition-fast);
}
.chat-messages::-webkit-scrollbar-thumb:hover {
background: var(--gray-400);
}
/* Empty State */
.chat-empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
text-align: center;
color: var(--gray-500);
padding: var(--space-8);
}
.chat-empty-state .empty-icon {
font-size: 4rem;
margin-bottom: var(--space-4);
opacity: 0.5;
}
.chat-empty-state h3 {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: var(--space-2);
color: var(--gray-700);
}
.chat-empty-state p {
font-size: 0.875rem;
max-width: 300px;
}
/* Mobile Responsive */
@media (max-width: 768px) {
.chat-interface {
padding: var(--space-2);
}
.chat-container {
height: calc(100vh - 1rem);
border-radius: var(--radius-xl);
}
.chat-header {
padding: var(--space-4);
}
.chat-header h1 {
font-size: 1.25rem;
}
.chat-messages {
padding: var(--space-4);
gap: var(--space-3);
}
.chat-message {
max-width: 90%;
padding: var(--space-3) var(--space-4);
font-size: 0.9rem;
}
.chat-input-container {
padding: var(--space-4);
gap: var(--space-2);
}
.upload-button,
.send-button {
width: 44px;
height: 44px;
font-size: 1.1rem;
}
}
@media (max-width: 480px) {
.chat-interface {
padding: var(--space-1);
}
.chat-container {
height: calc(100vh - 0.5rem);
border-radius: var(--radius-lg);
}
.chat-header {
padding: var(--space-3);
}
.chat-messages {
padding: var(--space-3);
}
.chat-message {
max-width: 95%;
padding: var(--space-3);
}
.chat-input-container {
padding: var(--space-3);
}
.message-input {
padding: var(--space-3) var(--space-4);
font-size: 0.95rem;
}
}
.home-container {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.home-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
background-color: #f8f9fa;
border-bottom: 1px solid #e9ecef;
}
.server-status {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.9rem;
}
.status-indicator {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
margin-left: 0.5rem;
}
.status-indicator.loading {
background-color: #ffc107;
animation: pulse 1.5s infinite;
}
.status-indicator.online {
background-color: #28a745;
}
.status-indicator.offline {
background-color: #dc3545;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.auth-nav {
display: flex;
gap: 1rem;
}
.auth-link {
color: #495057;
text-decoration: none;
padding: 0.5rem 1rem;
border-radius: 4px;
transition: background-color 0.2s;
}
.auth-link:hover {
background-color: #e9ecef;
}
.user-section {
display: flex;
align-items: center;
gap: 1rem;
}
.logout-button {
background: none;
border: none;
color: #dc3545;
cursor: pointer;
padding: 0.5rem 1rem;
border-radius: 4px;
}
.logout-button:hover {
background-color: #f8d7da;
}
.home-main {
flex: 1;
padding: 2rem;
max-width: 1200px;
margin: 0 auto;
width: 100%;
}
.hero-section {
text-align: center;
padding: 3rem 0;
margin-bottom: 2rem;
}
.hero-section h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
color: #343a40;
}
.hero-section p {
font-size: 1.2rem;
color: #6c757d;
max-width: 700px;
margin: 0 auto;
}
.features-section {
margin: 3rem 0;
}
.features-section h2 {
text-align: center;
margin-bottom: 2rem;
color: #343a40;
}
.feature-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
}
.feature-card {
background-color: white;
border-radius: 8px;
padding: 1.5rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.feature-card:hover {
transform: translateY(-5px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.feature-card h3 {
color: #343a40;
margin-bottom: 0.5rem;
}
.feature-card p {
color: #6c757d;
margin-bottom: 1rem;
}
.feature-link {
color: #007bff;
text-decoration: none;
font-weight: 500;
display: inline-block;
margin-top: 0.5rem;
}
.feature-link:hover {
text-decoration: underline;
}
.cta-section {
text-align: center;
padding: 3rem 0;
margin-top: 3rem;
background-color: #f8f9fa;
border-radius: 8px;
}
.cta-section h2 {
margin-bottom: 1.5rem;
color: #343a40;
}
.cta-buttons {
display: flex;
justify-content: center;
gap: 1rem;
}
.cta-button {
padding: 0.75rem 1.5rem;
border-radius: 4px;
text-decoration: none;
font-weight: 500;
transition: background-color 0.2s;
}
.cta-button.primary {
background-color: #007bff;
color: white;
}
.cta-button.primary:hover {
background-color: #0069d9;
}
.cta-button.secondary {
background-color: #6c757d;
color: white;
}
.cta-button.secondary:hover {
background-color: #5a6268;
}
.home-footer {
text-align: center;
padding: 1rem;
background-color: #f8f9fa;
border-top: 1px solid #e9ecef;
color: #6c757d;
font-size: 0.9rem;
}
\ No newline at end of file
export type MessageType = {
id: string;
content: string;
sender: 'user' | 'bot';
type: 'text' | 'image';
timestamp: Date;
};
\ No newline at end of file
from fastapi import FastAPI from fastapi import FastAPI
from src.infrastructure.api.fastapi.routes import auth, charts from src.infrastructure.api.fastapi.routes import auth, charts
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI( app = FastAPI(
title="Chart Analyzer API", title="Chart Analyzer API",
...@@ -7,6 +8,16 @@ app = FastAPI( ...@@ -7,6 +8,16 @@ app = FastAPI(
version="1.0.0", version="1.0.0",
) )
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"], # Your Vite frontend URL
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth.router, prefix="/auth") app.include_router(auth.router, prefix="/auth")
app.include_router(charts.router, prefix="/charts") app.include_router(charts.router, prefix="/charts")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment