Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

151 feedback form #164

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# VITE_API_BASE_URL=https://balancertestsite.com/
VITE_API_BASE_URL=http://localhost:8000
VITE_API_BASE_URL=https://balancertestsite.com/
# VITE_API_BASE_URL=http://localhost:8000
24 changes: 2 additions & 22 deletions frontend/src/components/Header/FeatureMenuDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ export const FeatureMenuDropDown = () => {
return (
<div className="h-50 absolute top-full mb-2 mt-2 flex flex-row items-center rounded-lg border-2 bg-white font-inter text-sm sm:px-6 md:px-8 lg:px-8 xl:px-6 ">
<div className="mx-3 my-5 ">
<Link to="/uploadfile">
<Link to="/AdminPortal">
<ul className=" cursor-pointer rounded-lg p-3 transition duration-300 hover:bg-gray-100">
<span className=" font-bold text-black ">
Manage Medication Suggester
</span>
<span className=" font-bold text-black ">Admin Portal</span>

<div className="mt-1 font-satoshi text-sm text-gray-400">
Set the settings for the Medication Suggester.
Expand All @@ -25,24 +23,6 @@ export const FeatureMenuDropDown = () => {
</ul>
</Link>

<Link to="/drugSummary">
<ul className=" cursor-pointer rounded-lg p-3 transition duration-300 hover:bg-gray-100">
<span className=" font-bold text-black ">
Knowledge Base (Brain)
</span>
<div className="mt-1 font-satoshi text-sm text-gray-400">
Manage and storage the Balancer-AI's brain.
</div>
</ul>
</Link>
<Link to="/drugSummary">
<ul className=" cursor-pointer rounded-lg p-3 transition duration-300 hover:bg-gray-100">
<span className=" font-bold text-black ">Task Manager</span>
<div className="mt-1 font-satoshi text-sm text-gray-400">
Control what Balancer-AI will do on its own.
</div>
</ul>
</Link>
<Link to="/settings">
<ul className=" cursor-pointer rounded-lg p-3 transition duration-300 hover:bg-gray-100">
<span className=" font-bold text-black ">Settings Manager</span>
Expand Down
27 changes: 23 additions & 4 deletions frontend/src/pages/AdminPortal/AdminPortal.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
//import Welcome from "../../components/Welcome/Welcome.tsx";
import Layout from "../Layout/Layout";
// import image from "./OIP.jpeg";
import { Link } from "react-router-dom";

function About() {
function AdminPortal() {
return (
<Layout>
<div className=" font_body mt-48 flex w-full flex-col items-center justify-center rounded-md border bg-white p-4 px-8 ring-1 hover:ring-slate-300 md:max-w-6xl"></div>
<div className="font_body mt-48 flex w-full flex-col items-center justify-center rounded-md border bg-white p-4 px-8 ring-1 hover:ring-slate-300 md:max-w-6xl">
<div className="flex flex-col items-center space-y-4 p-8">
<Link to="/UploadFile">
<button className="px-18 mt-1 w-80 rounded-xl bg-blue-500 py-2 text-xl text-white hover:bg-blue-600">
Upload File
</button>
</Link>
<Link to="/listoffiles">
<button className="px-18 mt-1 w-80 rounded-xl bg-blue-500 py-2 text-xl text-white hover:bg-blue-600">
List of Files
</button>
</Link>
<button className="px-18 mt-1 w-80 rounded-xl bg-blue-500 py-2 text-xl text-white hover:bg-blue-600">
Create process
</button>
</div>
{/* <div className="mt-8 text-sm text-gray-600">
<p>API status | Help & support</p>
</div> */}
</div>
</Layout>
);
}

export default About;
export default AdminPortal;
12 changes: 3 additions & 9 deletions frontend/src/pages/DocumentManager/UploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const UploadFile: React.FC = () => {
formData.append("file", file);

try {
const baseUrl = import.meta.env.VITE_API_BASE_URL;
const response = await axios.post(
"http://localhost:8000/v1/api/uploadFile",
`${baseUrl}/V1//api/uploadFile`,
formData,
{
headers: {
Expand Down Expand Up @@ -66,8 +67,7 @@ const UploadFile: React.FC = () => {
d="M3 15a4 4 0 004 4h10a4 4 0 004-4V7a4 4 0 00-4-4H7a4 4 0 00-4 4v8z"
/>
</svg>
<p className="mt-1 text-sm text-gray-500">Import a file</p>
<p className="mt-1 text-sm text-gray-500">PDF or Markdown</p>
<p className="mt-1 text-sm text-gray-500">Import a PDF</p>
</div>
<div className="mt-4">
<input
Expand All @@ -90,12 +90,6 @@ const UploadFile: React.FC = () => {
"Upload File"
)}
</button>
<button className="mt-2 w-full rounded-md bg-gray-100 px-4 py-2 text-gray-700">
Paste URL
</button>
<button className="mt-2 w-full rounded-md bg-gray-100 px-4 py-2 text-gray-700">
Paste text
</button>
</div>
</div>
</div>
Expand Down
90 changes: 90 additions & 0 deletions frontend/src/pages/Files/ListOfFiles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//import Welcome from "../../components/Welcome/Welcome.tsx";
import { useEffect, useState } from "react";
import axios from "axios";
import Layout from "../Layout/Layout";
// import { Link } from "react-router-dom";

interface File {
id: number;
guid: string;
file_name: string;
date_of_upload: string;
size: number;
page_count: number;
file_type: string;
uploaded_by_email: string;
source_url: string | null;
analyzed: boolean | null;
approved: boolean | null;
uploaded_by: number;
}
function ListOfFiles() {
const [files, setFiles] = useState<File[]>([]);
const [isLoading, setIsLoading] = useState(true);
// const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchFiles = async () => {
try {
const baseUrl = import.meta.env.VITE_API_BASE_URL;
const response = await axios.get(`${baseUrl}/v1/api/uploadFile`, {
headers: {
Authorization: `JWT ${localStorage.getItem("access")}`, // Assuming JWT is used for auth
},
});
console.log("Response data:", response.data);
if (Array.isArray(response.data)) {
setFiles(response.data);
} else {
// setError("Unexpected response format");
}
} catch (error) {
console.error("Error fetching files", error);
// setError("Error fetching files");
} finally {
setIsLoading(false);
}
};

fetchFiles();
}, []);

if (isLoading) {
return <div>Loading...</div>;
}
return (
<Layout>
<div className="font_body mt-48 flex w-full flex-col items-center justify-center rounded-md border bg-white p-4 px-8 ring-1 hover:ring-slate-300 md:max-w-6xl">
<div className="mt-8 text-sm text-gray-600">
<ul>
{files.map((file) => (
<li key={file.id} className="border-b p-4">
<p>
<strong>File Name:</strong> {file.file_name}
</p>
<p>
<strong>Date of Upload:</strong>{" "}
{new Date(file.date_of_upload).toLocaleString()}
</p>
<p>
<strong>Size:</strong> {file.size} bytes
</p>
<p>
<strong>Page Count:</strong> {file.page_count}
</p>
<p>
<strong>File Type:</strong> {file.file_type}
</p>
<p>
<strong>Uploaded By:</strong> {file.uploaded_by_email}
</p>
</li>
))}
</ul>
</div>
</div>
</Layout>
);
}

export default ListOfFiles;
27 changes: 11 additions & 16 deletions frontend/src/pages/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,17 @@ export const Layout = ({
const location = useLocation();

useEffect(() => {
// console.log(isAuthenticated);
if (!isAuthenticated) {
setShowLoginMenu(true);
}
if (location.pathname === "/login" && !isAuthenticated) {
setShowLoginMenu(false);
} else if (location.pathname === "/resetpassword" && !isAuthenticated) {
setShowLoginMenu(false);
} else if (
(location.pathname.includes("password") ||
location.pathname.includes("reset")) &&
!isAuthenticated
) {
setShowLoginMenu(false);
} else if (!isAuthenticated) {
setShowLoginMenu(true);
if (
location.pathname === "/login" ||
location.pathname === "/resetpassword" ||
location.pathname.includes("password") ||
location.pathname.includes("reset")
) {
setShowLoginMenu(false);
} else {
setShowLoginMenu(true);
}
}
}, [isAuthenticated, location.pathname]);

Expand All @@ -54,7 +49,7 @@ export const Layout = ({
<div className="gradient" />
</div>
<div className="relative z-10 mx-auto flex w-full flex-col items-center">
{!isAuthenticated && (
{!isAuthenticated && showLoginMenu && (
<LoginMenuDropDown
showLoginMenu={showLoginMenu}
handleLoginMenu={handleLoginMenu}
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/routes/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ import DataSources from "../pages/Help/DataSources.tsx";
import Settings from "../pages/Settings/Settings.tsx";
import ListMeds from "../pages/ListMeds/ListMeds.tsx";
import UploadFile from "../pages/DocumentManager/UploadFile.tsx";
import ListofFiles from "../pages/Files/ListOfFiles.tsx";
const routes = [
{
path: "/",
element: <App />,
errorElement: <RouteError />,
},
{
path: "listoffiles",
element: <ListofFiles />,
errorElement: <RouteError />,
},
{
path: "uploadfile",
element: <UploadFile />,
},
{
path: "drugSummary",
element: <DrugSummary />,
Expand Down Expand Up @@ -72,10 +82,6 @@ const routes = [
path: "medications",
element: <ListMeds />,
},
{
path: "uploadfile",
element: <UploadFile />,
},
];

export default routes;
6 changes: 6 additions & 0 deletions server/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
from .views.ai_promptStorage.models import AI_PromptStorage
from .views.ai_settings.models import AI_Settings
from .views.ai_promptStorage.models import AI_PromptStorage
from .models.model_embeddings import Embeddings
from .views.jira.models import Feedback


@admin.register(Embeddings)
class MedicationAdmin(admin.ModelAdmin):
list_display = ['guid']


@admin.register(Medication)
class MedicationAdmin(admin.ModelAdmin):
list_display = ['name', 'benefits', 'risks']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.3 on 2024-07-30 10:19

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0003_alter_uploadfile_date_of_upload_and_more'),
]

operations = [
migrations.AddField(
model_name='uploadfile',
name='uploaded_by_email',
field=models.CharField(blank=True, max_length=255),
),
migrations.AlterField(
model_name='uploadfile',
name='uploaded_by',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
30 changes: 30 additions & 0 deletions server/api/migrations/0005_embeddings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.3 on 2024-07-30 10:21

from django.db import migrations, models
import django.db.models.deletion
import pgvector.django.vector
import uuid


class Migration(migrations.Migration):

dependencies = [
('api', '0004_uploadfile_uploaded_by_email_and_more'),
]

operations = [
migrations.CreateModel(
name='Embeddings',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('guid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('name', models.CharField(max_length=255)),
('text', models.TextField()),
('page_num', models.IntegerField(default=1)),
('chunk_number', models.IntegerField()),
('embedding_sentence_transformers', pgvector.django.vector.VectorField(dimensions=384, null=True)),
('date_of_upload', models.DateTimeField(auto_now_add=True)),
('upload_file', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='embeddings', to='api.uploadfile')),
],
),
]
22 changes: 22 additions & 0 deletions server/api/models/model_embeddings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import models
from django.conf import settings
from pgvector.django import VectorField
import uuid
from ..views.uploadFile.models import UploadFile


class Embeddings(models.Model):
upload_file = models.ForeignKey(
UploadFile, related_name='embeddings', on_delete=models.CASCADE)
# This is a new unique GUID for each Embedding
guid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255)
text = models.TextField()
page_num = models.IntegerField(default=1)
chunk_number = models.IntegerField()
embedding_sentence_transformers = VectorField(
dimensions=384, null=True)
date_of_upload = models.DateTimeField(auto_now_add=True, blank=True)

def __str__(self):
return self.name
12 changes: 12 additions & 0 deletions server/api/services/conversions_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import uuid


def convert_uuids(data):
if isinstance(data, dict):
return {key: convert_uuids(value) for key, value in data.items()}
elif isinstance(data, list):
return [convert_uuids(item) for item in data]
elif isinstance(data, uuid.UUID):
return str(data)
else:
return data
Loading