Skip to content

Commit

Permalink
Merge pull request #160 from AI4Bharat/btns
Browse files Browse the repository at this point in the history
Btns
  • Loading branch information
aparna-aa authored Oct 14, 2024
2 parents f345fa3 + be46a42 commit a85c14d
Show file tree
Hide file tree
Showing 30 changed files with 3,484 additions and 145 deletions.
219 changes: 176 additions & 43 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
"chart.js": "^4.4.1",
"date-fns": "^3.2.0",
"dotenv": "^16.4.5",
"export-from-json": "^1.7.4",
"firebase": "^10.7.1",
"firebase-auth": "^0.1.2",
"franc-min": "^6.2.0",
"html-react-parser": "^5.1.10",
"html2canvas": "^1.4.1",
"install": "^0.13.0",
"jspdf": "^2.5.1",
"jspdf": "^2.5.2",
"mui-datatables": "^4.3.0",
"next": "^14.0.4",
"next-redux-wrapper": "^8.1.0",
Expand All @@ -41,6 +42,8 @@
"react-chartjs-2": "^5.2.0",
"react-csv": "^2.2.2",
"react-date-range": "^2.0.0-alpha.4",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18",
"react-drag-drop-files": "^2.3.10",
"react-hook": "^0.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/Lib/Features/Analytics/Workspace/wsgetMetaAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ENDPOINTS from "../../../../config/apiendpoint"

const initialState = {
data: [],
originalData: [],
status: 'idle',
error: null,
};
Expand Down Expand Up @@ -75,6 +76,7 @@ const getwsMetaAnalyticsData = createSlice({
const data = diffAnnotationReview(action.payload);
state.status = 'succeeded';
state.data = data;
state.originalData = action.payload
})
.addCase(fetchwsMetaAnalyticsData.rejected, (state, action) => {
state.status = 'failed';
Expand Down
2 changes: 2 additions & 0 deletions src/Lib/Features/Analytics/Workspace/wsgetTaskAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ENDPOINTS from "../../../../config/apiendpoint";

const initialState = {
data: [],
originalData: [],
status: 'idle',
error: null,
};
Expand Down Expand Up @@ -55,6 +56,7 @@ const getwsTaskAnalyticsData = createSlice({
const data = diffAnnotationReview(action.payload);
state.status = 'succeeded';
state.data = data;
state.originalData = action.payload
})
.addCase(fetchwsTaskAnalyticsData.rejected, (state, action) => {
state.status = 'failed';
Expand Down
2 changes: 2 additions & 0 deletions src/Lib/Features/Analytics/getMetaAnalyticsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ENDPOINTS from "../../../config/apiendpoint"

const initialState = {
data: [],
originalData:[],
status: 'idle',
error: null,
};
Expand Down Expand Up @@ -75,6 +76,7 @@ const getMetaAnalyticsData = createSlice({
const data = diffAnnotationReview(action.payload);
state.status = 'succeeded';
state.data = data;
state.originalData = action.payload;
})
.addCase(fetchMetaAnalyticsData.rejected, (state, action) => {
state.status = 'failed';
Expand Down
2 changes: 2 additions & 0 deletions src/Lib/Features/Analytics/getTaskAnalyticsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ENDPOINTS from "../../../config/apiendpoint";

const initialState = {
data: [],
originalData: [],
status: 'idle',
error: null,
};
Expand Down Expand Up @@ -55,6 +56,7 @@ const getTaskAnalyticsData = createSlice({
const data = diffAnnotationReview(action.payload);
state.status = 'succeeded';
state.data = data;
state.originalData = action.payload;
})
.addCase(fetchTaskAnalyticsData.rejected, (state, action) => {
state.status = 'failed';
Expand Down
131 changes: 89 additions & 42 deletions src/app/new-project/newproject.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { fetchDataitemsById } from "@/Lib/Features/datasets/GetDataitemsById";
import { fetchWorkspaceDetails } from "@/Lib/Features/getWorkspaceDetails";
import { Visibility, VisibilityOff } from "@mui/icons-material";
import UploadIcon from '@mui/icons-material/Upload';
import sampleQuestion from './sampleQue';
const isNum = (str) => {
var reg = new RegExp("^[0-9]*$");
return reg.test(String(str));
Expand All @@ -63,12 +64,11 @@ const CreateAnnotationsAutomatically = [


const CreateProject = () => {
/* eslint-disable react-hooks/exhaustive-deps */

const router = useRouter();
const dispatch = useDispatch();
const { id } = useParams();
//remove this line:
//and uncomment this after implementing dynamic routes:
//const { workspaceId } = useParams();
const ProjectDomains = useSelector(state => state.domains?.domains);
const ProjectDomains1 = useSelector(state => console.log(state));
Expand Down Expand Up @@ -124,25 +124,57 @@ const CreateProject = () => {
const [passwordForProjects, setPasswordForProjects] = useState("");
const [shownewpassword, setShowNewPassword] = useState(false);
const [csvFile, setCsvFile] = useState(null);
const [questionsJSON, setQuestionsJSON] = useState([]);

/* eslint-disable react-hooks/exhaustive-deps */
const [jsonInput, setJsonInput] = useState(JSON.stringify(sampleQuestion));
const [questionsJSON, setQuestionsJSON] = useState(sampleQuestion);

const handleJsonInputChange = (event) => {
const input = event.target.value;

setJsonInput(input);
try {
const parsedInput = JSON.parse(input);
console.log("parsed input: ", parsedInput);
const parsedInput = JSON.parse(input);
if (Array.isArray(parsedInput) && parsedInput.every(item => typeof item === 'object' && item !== null)) {
setQuestionsJSON(parsedInput);
setQuestionsJSON(parsedInput);
} else {
console.error("Input is not a valid array of objects");
}
} catch (error) {
console.error("Invalid JSON input");
console.error("Invalid JSON input");
}
};
useEffect(() => {

const handleCsvUpload = (event) => {
const file = event.target.files[0];

if (file) {
const reader = new FileReader();
reader.onload = (e) => {
const csvData = e.target.result;

try {
const csvJson = convertCsvToJson(csvData);
setJsonInput(JSON.stringify(csvJson, null, 2));
setQuestionsJSON(csvJson);
} catch (error) {
console.error("Error parsing CSV:", error);
}
};
reader.readAsText(file);
}
};

const convertCsvToJson = (csvData) => {
const rows = csvData.split("\n").filter(row => row.trim() !== "");
const headers = rows[0].split(",");
return rows.slice(1).map(row => {
const values = row.split(",");
let obj = {};
headers.forEach((header, index) => {
obj[header.trim()] = values[index].trim();
});
return obj;
});
};
useEffect(() => {
console.log('questionsJSON:', questionsJSON);
console.log('typeof questionsJSON:', typeof questionsJSON);
console.log('Array.isArray(questionsJSON):', Array.isArray(questionsJSON));
Expand Down Expand Up @@ -271,7 +303,6 @@ const CreateProject = () => {
if(questionsJSON[0]?.mandatory) console.log("this is true")
else console.log("this is false");
/* eslint-disable react-hooks/exhaustive-deps */
// console.log("now the questions is: " + typeof(questionsJSON))
const searchOpen = Boolean(searchAnchor);
const excludeKeys = [
"parent_data_id",
Expand Down Expand Up @@ -483,14 +514,43 @@ const CreateProject = () => {
password: passwordForProjects,
metadata_json: questionsJSON
};
console.log(newProject);

if (sourceLanguage) newProject["src_language"] = sourceLanguage;
if (targetLanguage) newProject["tgt_language"] = targetLanguage;

dispatch(createProject(newProject));

};


const newProject = {
title: title,
description: description,
created_by: UserData?.id,
is_archived: false,
is_published: false,
users: [UserData?.id],
workspace_id: id,
organization_id: UserData?.organization?.id,
project_type: selectedType,
src_language: sourceLanguage,
tgt_language: targetLanguage,
dataset_id: selectedInstances,
label_config: "string",
sampling_mode: samplingMode,
sampling_parameters_json: samplingParameters,
batch_size:batchSize,
batch_number:batchNumber,
// variable_parameters: selectedVariableParameters,
filter_string: filterString,
project_stage: taskReviews,
required_annotators_per_task: selectedAnnotatorsNum,
automatic_annotation_creation_mode: createannotationsAutomatically,
is_published:is_published,
password: passwordForProjects,
metadata_json: questionsJSON
};
console.log(newProject);

const setPasswordForNewProject = async (projectId) => {
try {
Expand Down Expand Up @@ -1250,36 +1310,23 @@ const CreateProject = () => {
Upload CSV or Paste JSON<span style={{ color: '#d93025' }}>*</span> :
</Typography>

<Grid container item xs={12} style={{ marginTop: '20px', alignItems: 'center' }}>
<TextField
variant="outlined"
multiline
rows={4}
value={JSON.stringify(questionsJSON)}
onChange={handleJsonInputChange}
style={{ flex: 1, marginRight: '10px' }}
/>
<input
type="file"
accept=".csv"
onChange={handleCsvUpload}
style={{ marginBottom: '20px' }}
/>

<Grid container item xs={12} style={{ marginTop: '20px', alignItems: 'center' }}>
<TextField
variant="outlined"
multiline
rows={4}
value={jsonInput}
onChange={handleJsonInputChange}
style={{ flex: 1, marginRight: '10px' }}
/>

<InputLabel htmlFor="csv-file-input" style={{ display: 'none' }}>
Upload CSV File
</InputLabel>
<input
id="csv-file-input"
type="file"
accept=".csv"
onChange={handleFileChange}
style={{ display: 'none' }}
/>
<label htmlFor="csv-file-input">
<Button
variant="contained"
color="primary"
component="span"
startIcon={<UploadIcon />}
>
Upload CSV
</Button>
</label>
</Grid>
</Grid>

Expand Down
7 changes: 7 additions & 0 deletions src/app/new-project/sampleQue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import ReviewPage from "./ui/pages/chat/ReviewPage";
import AnnotatePage from "./ui/pages/chat/AnnotatePage";
import SuperCheckerPage from "./ui/pages/chat/SuperCheckerPage";
import CreateProject from "./new-project/newproject";
import OutputSelection from "./ui/pages/dual-screen-preference-ranking/PreferenceRanking";
import PreferenceRanking from "./ui/pages/n-screen-preference-ranking/PreferenceRanking";

export default function Root() {
if (typeof window !== 'undefined') {
Expand Down Expand Up @@ -73,6 +75,18 @@ export default function Root() {
element={ProtectedRouteWrapper(
<Layout component={<Projects />} Backbutton={true} backPressNavigationPath={"/projects"} />
)}
/>
<Route
path="pre"
element={ProtectedRouteWrapper(
<Layout component={<OutputSelection />} Backbutton={true} backPressNavigationPath={"/projects"} />
)}
/>
<Route
path="pref"
element={ProtectedRouteWrapper(
<Layout component={<PreferenceRanking />} Backbutton={true} backPressNavigationPath={"/projects"} />
)}
/>
<Route
path="datasets/:datasetId/datasetsetting"
Expand Down
Loading

0 comments on commit a85c14d

Please sign in to comment.