Skip to content
Snippets Groups Projects
Commit a1cf42e0 authored by Tarek Shah's avatar Tarek Shah
Browse files

mutli summary working

parent e18f3bf3
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
No preview for this file type
{"Users": 2, "Collections": 1}
\ No newline at end of file
{"Users": 2, "Collections": 2}
\ No newline at end of file
File added
......@@ -20,17 +20,6 @@ import CollectionEditor from './collection_editor';
import { dbGetCollections, dbGetItems } from './database_util';
const dummy_collection_data = [
{
"title":"My Test Collection"
},
{
"title":"My Second Test Collection"
},
];
function App() {
const [foo, setFoo] = useState('');
const [authenticated, setAuthenticated] = useState(false);
......@@ -88,12 +77,6 @@ function App() {
},[loadedRawFiles,loadedLinkFiles,loadedXMLFiles]
);
// useEffect(
// () => {
// console.log("Updated authentication",authenticated);
// },[authenticated]
// );
useEffect(
() => {
console.log("Updated loaded collections",loadedCollections);
......@@ -115,14 +98,6 @@ function App() {
},[selectedCollection]
);
// const displayLoginStatus = () => {
// if (authenticated) {
// return "User: " + username + ", Password: " + password
// } else {
// return "Log in"
// }
// };
const showEditor= () => {
if (selectedCollection == null) {
return (<h1>Select/Create a Collection</h1>);
......@@ -226,19 +201,6 @@ function App() {
</Grid>
</Grid>
</Box>
{/* testing */}
{/* <Button
component="label"
// role={undefined}
variant="contained"
tabIndex={-1}
>
Upload File
<input type="file" hidden/>
</Button>
<input type="file" onChange={onFileChange} name="plaintext1"/> */}
</Box>
</div>
);
......
......@@ -22,7 +22,9 @@ const CollectionEditor = (props) => {
}
const [summaries, setSummaries] = useState([]);
const summary_array = () => {
return [["T5",props.collection["t5_summary"]], ["NLTK", props.collection["nltk_summary"]], ["BERT",props.collection["bert_summary"]]]
}
const generateSummary = async () => {
if (summarizer === '') {
......@@ -30,57 +32,12 @@ const CollectionEditor = (props) => {
}
setOpen(true);
let id = props.collection["collection_id"]
let newSummary = "";
const existingIndex = summaries.findIndex(summary => {
if (summary && summary.key.startsWith(summarizer.replace(" ", ""))) {
return true;
}
return false;
});
let newTextField;
if (existingIndex !== -1) {
// Update the existing summary
const existingSummary = summaries[existingIndex];
await updateCollectionSummary(id);
props.onCollectionUpdate(await dbGetCollection(id));
setOpen(false);
newTextField = <TextField disabled multiline maxRows={20} fullWidth label="Summary:" value={props.collection[`${summarizer}_summary`]} />;
newSummary = React.cloneElement(existingSummary, {}, [<h3>{summarizer.toUpperCase()} Summary:</h3>, newTextField]);
const updatedSummaries = [...summaries];
updatedSummaries[existingIndex] = newSummary;
setSummaries(updatedSummaries);
} else {
// Create a new summary
await updateCollectionSummary(id);
props.onCollectionUpdate(await dbGetCollection(id));
setOpen(false);
newTextField = <TextField disabled multiline maxRows={20} fullWidth label="Summary:" value={props.collection[`${summarizer}_summary`]} />;
newSummary = <div key={`${summarizer.replace(" ", "")}Summary`}><h3>{summarizer.toUpperCase()} Summary:</h3>{newTextField}</div>;
setSummaries([...summaries, newSummary]);
}
}
const updateCollectionSummary = async (id) => {
switch (summarizer) {
case "t5":
await dbUpdateCollectionSummary(id);
break;
case "bert":
await dbUpdateCollectionSummaryBERT(id);
break;
case "nltk":
await dbUpdateCollectionSummaryNLTK(id);
break;
default:
break;
}
await dbUpdateCollectionSummary(id, summarizer);
props.onCollectionUpdate(await dbGetCollection(id));
setOpen(false);
}
// console.log("loadedRawFiles", props.loadedRawFiles)
return (
<Box>
<h1>{props.collection["collection_name"]}</h1>
......@@ -118,10 +75,19 @@ const CollectionEditor = (props) => {
</Select>
</ListItem>
</List>
{/* <h3>Generated Summary:</h3>
<TextField disabled multiline maxRows={20} fullWidth label="Summary:" value={props.collection["collection_summary"]}/> */}
<Button onClick={generateSummary}>Generate Summary</Button>
{summaries.map((summary) => summary)}
{
summary_array().map((f) => {
return (
<div>
<h3>{f[0]}</h3>
<TextField disabled multiline maxRows={20} fullWidth label="Summary:" value={f[1]} />
</div>
);
})
}
{/* {summaries.map((summary) => summary)} */}
<Backdrop
open={open}
......
......@@ -101,10 +101,10 @@ export const dbUpdateCollectionGlob = async (collection_id,glob) => {
return result
};
export const dbUpdateCollectionSummary = async (collection_id) => {
export const dbUpdateCollectionSummary = async (collection_id, summarizer) => {
console.log("dbUpdateCollectionSummary",collection_id);
let result = await fetch(
"http://127.0.0.1:5000/api/v1/summarize/t5",
`http://127.0.0.1:5000/api/v1/summarize/${summarizer}`,
{
method: "POST", // or 'PUT'
headers: {
......@@ -206,61 +206,4 @@ export const dbUploadUrlFile = async (collection_id,formData) => {
return result
};
export const dbUpdateCollectionSummaryNLTK = async (collection_id) => {
let result = await fetch(
"http://127.0.0.1:5000/api/v1/summarize/nltk",
{
method: "POST", // or 'PUT'
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
{
"collection_info":{
"collection_id": collection_id,
}
}
),
}
)
.then((response) => response.json())
.then((response) => {
if (response["status"] === "success") {
return response;
}
});
return result
};
export const dbUpdateCollectionSummaryBERT = async (collection_id) => {
let result = await fetch(
"http://127.0.0.1:5000/api/v1/summarize/bert",
{
method: "POST", // or 'PUT'
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
{
"collection_info":{
"collection_id": collection_id,
}
}
),
}
)
.then((response) => response.json())
.then((response) => {
if (response["status"] === "success") {
return response;
}
});
return result
};
export default dbCreateCollection;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment