Spaces:
Running
Running
File size: 23,559 Bytes
8f2f1a5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
import React, { useState, useRef } from "react";
import "./App.css";
import { RQicon } from './mysvg'
import { Button, Divider, Form, Input, Layout, Space, Table, notification } from "antd";
import { Content, Footer, Header } from "antd/es/layout/layout";
import { SearchOutlined } from '@ant-design/icons';
import TextArea from "antd/es/input/TextArea";
import FullPageLoader from "./FullPageLoader";
import { answers, columns, filterColumns, paperColumns } from "./columns";
function App() {
const [loading, setLoading] = useState(false)
const contentRef = useRef();
const scrollToBottom = () => {
let elem = document.getElementById("mainContainer")
setTimeout(()=>{
elem.scroll(0,elem.scrollHeight)
}, 300)
};
const [name, setName] = useState("'My work aims to systematically identify and analyze, the literature on Large language models in software development'");
const [noOfQuestion, setNoOfQuestions] = useState(2)
const [researchQuestions, setResearchQuestions] = useState([])
const [researchQuestionApiResponse, setResearchQuestionApiResponse] = useState()
const [searchString, setSearchString] = useState('')
const [start_year, setstartYear] = useState(2023)
const [end_year, setEndYear] = useState(2020)
const generateSearchString = async (e) => {
e.preventDefault();
try {
setLoading(true)
const response = await fetch("/api/generate_search_string", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
objective: name,
research_questions: researchQuestions
})
});
const message = await response.json();
setSearchString(
message.search_string
.replace(/^\d+\.\s*/, '') // Remove any leading digits and dots
.replace(/\bAND\b/g, 'OR') // Replace "AND" with "OR"
.replace(/[()]/g, '') // Remove parentheses
);
setLoading(false)
scrollToBottom()
notification.success({
message:"Search String Generated"
})
} catch (e) {
notification.error({
message: `internal Server Error`
})
setLoading(false)
}
}
const [papersData, setPapersData] = useState()
const [limitPaper, setLimitPaper] = useState(10)
const fetchAndSavePapers = async (e) => {
e.preventDefault();
try {
setLoading(true)
const response = await fetch("/api/search_papers", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
search_string: searchString,
start_year: start_year,
limit: limitPaper
})
});
const message = await response.json();
if (message) {
setPapersData(message)
}
scrollToBottom()
setLoading(false)
notification.success({
message:"Papers Found"
})
} catch (e) {
console.log("error:", e)
setLoading(false)
notification.error({
message:"Internal Server Error"
})
}
}
const handleSubmit = async (e) => {
e.preventDefault();
try {
setLoading(true)
const response = await fetch("/api/generate_research_questions_and_purpose", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
objective: name,
num_questions: noOfQuestion
}),
});
const message = await response.json();
let dataResponse = message.research_questions.research_questions.map((i, index) => ({ ...i, key: index }))
console.log("response:", dataResponse);
setResearchQuestionApiResponse(dataResponse)
let questions = message.research_questions.research_questions.map(i => i.question)
setResearchQuestions(questions)
setLoading(false)
scrollToBottom()
notification.success({
message:"Research Questions Generated"
})
} catch (error) {
console.error("Error submitting data:", error);
setLoading(false)
notification.error({
message:"Internal Server Error"
})
}
};
const [papersFilterData, setPapersFilterData] = useState([])
const handleCheckboxChange = (key) => {
const newpapersFilterData = [...papersFilterData];
if (newpapersFilterData.includes(key)) {
newpapersFilterData.splice(newpapersFilterData.indexOf(key), 1);
} else {
newpapersFilterData.push(key);
}
setPapersFilterData(newpapersFilterData);
};
const fetchAndFilterPapers = async (e) => {
e.preventDefault();
try {
setLoading(true)
const response = await fetch("/api/filter_papers", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
search_string: searchString,
papers: papersData
})
});
const message = await response.json();
if (message) {
const newFilteredPapers = message.filtered_papers;
const combinedArray = [...new Set([...papersFilterData, ...newFilteredPapers])];
setPapersFilterData(combinedArray);
}
scrollToBottom()
setLoading(false)
notification.success({
message:"Papers Filtered"
})
} catch (e) {
console.log("error:", e)
setLoading(false)
notification.error({
message:"internal server error"
})
}
}
const [ansWithQuestions, setAnsWithQuestionsData] = useState()
const ansWithQuestionsData = async (e) => {
e.preventDefault();
try {
setLoading(true)
const response = await fetch("/api/answer_question", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
questions: researchQuestions,
papers_info: [...new Set([...papersFilterData, ...papersFilterData])]
})
});
const message = await response.json();
console.log("message:", message)
if (message) {
setAnsWithQuestionsData(message.answers)
}
setLoading(false)
notification.success({
message:"Answers Generated"
})
scrollToBottom()
} catch (e) {
console.log("error:", e)
setLoading(false)
notification.error({
message:"Internal Server Error"
})
}
}
const [summary, setSummary] = useState()
const [introSummary, setIntroSummary] = useState()
const generateSummaryAbstract = async (e) =>{
e.preventDefault()
setLoading(true)
try{
let response = await fetch ("api/generate-summary-abstract", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
questions: researchQuestions,
objective: name,
search_string: searchString
})
});
let message = await response.json()
setSummary(message.summary_abstract)
setLoading(false)
notification.success({
message:"Summary Abstract Generated"
})
scrollToBottom()
}catch(error) {
setLoading(false)
console.log("error:", error)
}
}
const introductionSummary = async (e) =>{
e.preventDefault()
setLoading(true)
try{
let response = await fetch ("api/generate-introduction-summary", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
questions: researchQuestions,
objective: name,
search_string: searchString,
total_papers: papersData,
filtered_papers: papersFilterData,
answers: ansWithQuestions
})
});
let message = await response.json()
setIntroSummary(message.introduction_summary)
setLoading(false)
notification.success({
message:"Introduction Summary Generated"
})
scrollToBottom()
}catch(error) {
setLoading(false)
console.log("error:", error)
}
}
const [downloadlink, setDownloadLink] = useState()
const generateAllSummary = async (e) =>{
e.preventDefault()
setLoading(true)
try{
let response = await fetch ("api/generate-summary-all", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
abstract_summary: summary,
intro_summary: introSummary,
conclusion_summary: summary
})
});if (!response.ok) {
throw new Error(`Error: ${response.status} - ${response.statusText}`);
}
const blob = await response.blob();
const contentDisposition = response.headers.get('Content-Disposition');
const filename = contentDisposition ? contentDisposition.split('filename=')[1] : 'paper_summary.tex';
const url = window.URL.createObjectURL(new Blob([blob]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(link);
setLoading(false)
}catch(error) {
setLoading(false)
console.log("error:", error)
}
}
const handleTextareaChange = (event) => {
const newText = event.target.value;
const modifiedString = newText.replace(/^Question \d+: /gm, '');
console.log("modified value",modifiedString.trim());
// console.log("question value:", event.target.value)
const newQuestions = modifiedString.split('\n').map((question) => question);
setResearchQuestions(newQuestions);
};
const handleSearchStringChange = (event) => {
if(event.target.value == ""){
setSearchString(" ")
}else{
setSearchString(event.target.value);
}
};
return (
<Layout>
<Header style={{ backgroundColor: "#f3fff3", }} >
<div style={{ display: "flex", flexDirection: "row", justifyContent: "space-between", marginLeft: "0px" }}>
<div>
<RQicon width={"60px"} height={"60px"} />
</div>
<div style={{ fontSize: "20px", color: "black" }}>
<strong >SLR Automation Tool</strong>
</div>
<div>
</div>
</div>
</Header>
<Layout>
<Content>
{loading && <FullPageLoader/>}
<div
id="mainContainer"
style={{
// paddingTop:"150px",
lineHeight: "0px",
display: "flex",
flexDirection: "column",
// justifyContent: "center",
// alignContent: "center",
alignItems: "center",
overflowY: "auto",
height: "85vh",
paddingBottom:"30px"
}}
ref={contentRef}
>
<div>
<div>
{/* <div style={{textAlign:"center"}}><RQicon width={"100px"} height={"100px"} /></div> */}
<h5>Hello, I am your Agent, Enter Your Research Objective.</h5>
</div>
<div style={{ display: 'flex', alignItems: 'center', width: "80vw", border: '1px solid #ccc', padding: 15, marginBottom: 5, borderRadius: "10px" }}>
<Form layout="vertical" style={{ width: "100%", display: "flex", alignItems: "center" }}>
<Form.Item label="Objective" style={{ flex: "1 1 70%", marginRight: '5px' }}>
<Input
placeholder="Ask me anything..."
value={name}
onChange={(e) => setName(e.target.value)}
/>
</Form.Item>
<Form.Item label="No of Questions" style={{ flex: 1, marginRight: '5px' }}>
<Input
placeholder="Number of Questions"
min={1}
max={5}
value={noOfQuestion}
onChange={(e) => setNoOfQuestions(e.target.value)}
type="number"
/>
</Form.Item>
<Form.Item style={{marginBottom:"-4px"}}>
<Button
type="primary"
icon={<SearchOutlined />}
onClick={handleSubmit}
>
Search
</Button>
</Form.Item>
</Form>
</div>
</div>
{researchQuestionApiResponse &&
<div style={{ display: 'flex', alignItems: 'center', width: "80vw", border: '1px solid #ccc', padding: 10, borderRadius: "10px", marginBottom:5 }}>
<Space direction="vertical" style={{ width: "100%", padding: "10px 0px" }} >
<Table scroll={{
x: 1200,
y: 500,
}} style={{width:'100%'}} dataSource={researchQuestionApiResponse} columns={columns} pagination={false} />
</Space>
</div>}
{researchQuestions && researchQuestions.length > 0 &&
<div style={{ display: 'flex', flexDirection: "column", alignItems: 'center', width: "80vw", border: '1px solid #ccc', padding: 10, borderRadius: "10px" }}>
<div>
<Space align="center" direction="vertical" style={{ display: 'flex', justifyContent: 'center' }}>
<Form layout="vertical">
<Form.Item label="List Of Questions">
<TextArea style={{ width: "70vw" }} onChange={handleTextareaChange} value={researchQuestions.map((question, index) => question.length == 0 ?"":`Question ${index + 1}: ${question}`).join('\n')} rows={researchQuestions.length} />
</Form.Item>
<Button type="primary" style={{ width: "auto", float: 'right' }} onClick={generateSearchString}>Create Search String</Button>
</Form>
</Space>
</div>
{searchString && searchString.length > 0 && <div>
<div>
<Divider />
<Space align="center" direction="vertical" style={{ display: 'flex', justifyContent: 'center' }}>
<Form layout="vertical">
<Form.Item label="Search String">
<TextArea onChange={handleSearchStringChange} value={searchString} rows={3} style={{ width: "70vw" }} />
</Form.Item>
{/* <Space.Compact> */}
<Form.Item label="Year" style={{width:"70vw"}}>
<Input type="number" max={2024} min={2014} value={start_year} onChange={(e) => setstartYear(e.target.value)} />
</Form.Item>
<Form.Item label="No of Papers" style={{width:"70vw"}}>
<Input type="number" max={15} min={5} value={limitPaper} onChange={(e)=> setLimitPaper(e.target.value)} placeholder="No Of Papers"/>
</Form.Item>
{/* </Space.Compact> */}
<Button type="primary" style={{ width: "auto", float: 'right' }} onClick={fetchAndSavePapers}>Fetch Papers</Button>
</Form>
</Space>
</div>
</div>}
{papersData &&
<><Divider />
<Space direction="vertical" style={{ width: "100%", padding: "10px 0px" }} >
<Table scroll={{
x: 1500,
y: 450,
}} style={{ width: "100%" }} dataSource={papersData} columns={paperColumns(papersFilterData, handleCheckboxChange)} pagination={false} />
<Button type="primary" style={{ float: "right", marginTop: "10px" }} onClick={fetchAndFilterPapers}>Filter with title</Button>
</Space></>
}
{(papersFilterData.length >0 || papersFilterData.length >0) && <Space direction="vertical" style={{ width: "100%", padding: "10px 0px" }} >
<Table scroll={{
x: 1500,
y: 450,
}} dataSource={[...new Set([...papersFilterData, ...papersFilterData])]} columns={filterColumns} pagination={false} />
{(papersFilterData.length > 0 || papersFilterData.length > 0) && <Button type="primary" style={{ float: "right", marginTop: "10px" }} onClick={ansWithQuestionsData}>Find Answers of Each Question </Button>}
</Space>}
{ansWithQuestions &&
<Space direction="vertical" style={{ width: "100%", padding: "10px 0px" }}>
<Table dataSource={ansWithQuestions} columns={answers} pagination={false} />
<Button type="primary" style={{float:"right", marginTop:"10px"}} onClick={generateSummaryAbstract}>Generate Summary Abstract </Button>
</Space>
}
{summary && summary.length >0 && <><Divider />
<Space align="center" direction="vertical" style={{ display: 'flex', justifyContent: 'center' }}>
<Form layout="vertical">
<Form.Item label="Summary Abstract">
<TextArea onChange={(e)=> setSummary(e.target.value)} value={summary} rows={7} style={{ width: "70vw" }} />
</Form.Item>
<Button type="primary" style={{ width: "auto", float: 'right' }} onClick={introductionSummary}>Introduction Summary</Button>
</Form>
</Space>
</>}
{introSummary && introSummary.length >0 && <><Divider />
<Space align="center" direction="vertical" style={{ display: 'flex', justifyContent: 'center' }}>
<Form layout="vertical">
<Form.Item label="Introduction Summary">
<TextArea onChange={(e)=> setIntroSummary(e.target.value)} value={introSummary} rows={7} style={{ width: "70vw" }} />
</Form.Item>
<Button type="primary" style={{ width: "auto", float: 'right' }} onClick={generateAllSummary}>Create Paper Summary</Button>
{downloadlink && downloadlink.length>0 && <a href={downloadlink} >download file</a> }
</Form>
</Space>
</>}
</div>}
</div>
</Content>
</Layout>
<Footer className="footerFixed">
<div style={{float:"right", lineHeight:0}}>
<p>© {new Date().getFullYear()} SLR Automation Tool. All rights reserved. </p>
</div>
</Footer>
</Layout>
);
}
export default App; |