CoolFace
Apppublic

itsprasun/pythonic-rag-fastapi-react

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
App.tsx56 linesDownload Raw Back to src
1import React, { useState } from "react";2import ChatInterface from "./components/ChatInterface";3 4const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || "";5 6console.log("API_BASE_URL:", API_BASE_URL);7 8const App: React.FC = () => {9  const [pipelineId, setPipelineId] = useState<string | null>(null);10 11  const handleFileUpload = async (file: File) => {12    const formData = new FormData();13    formData.append("file", file);14 15    const url = `${API_BASE_URL}/api/upload`;16    console.log("Uploading file to:", url);17 18    try {19      const response = await fetch(url, {20        method: "POST",21        body: formData,22      });23 24      if (!response.ok) {25        const errorData = await response.json().catch(() => ({}));26        throw new Error(errorData.detail || "Upload failed");27      }28 29      const data = await response.json();30      console.log("Upload response:", data);31      setPipelineId(data.pipeline_id);32    } catch (error) {33      console.error("Error uploading file:", error);34      throw error;35    }36  };37 38  return (39    <div className="min-h-screen bg-gray-900">40      <header className="bg-gray-800 border-b border-gray-700">41        <div className="max-w-7xl mx-auto py-4 px-4">42          <h1 className="text-2xl font-bold text-white">Document Q&A Chat</h1>43        </div>44      </header>45      <main className="max-w-7xl mx-auto">46        <ChatInterface47          pipelineId={pipelineId}48          onFileUpload={handleFileUpload}49        />50      </main>51    </div>52  );53};54 55export default App;56