Skip to content

Commit

Permalink
fixed web page bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
4darsh-Dev committed May 24, 2024
1 parent f8f36ea commit a5d2de6
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 160 deletions.
7 changes: 5 additions & 2 deletions django-backend/mlApi/bert_darkp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Implementing TowardsDS's BERT model for dark pattern detection
# Implementing TowardsDS's BERT model for dark pattern detection traning for mulit-class classification

import torch
from tqdm import tqdm
Expand Down Expand Up @@ -151,7 +151,7 @@ def accuracy_per_class(preds, labels):

## TraningLoop for BERT

# for loading cpu model on gpu
# for loading model on gpu
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")


Expand All @@ -163,6 +163,8 @@ def accuracy_per_class(preds, labels):
torch.manual_seed(seed_val)
torch.cuda.manual_seed_all(seed_val)

# evaluating the model

def evaluate(dataloader_val):

model.eval()
Expand Down Expand Up @@ -230,6 +232,7 @@ def evaluate(dataloader_val):
progress_bar.set_postfix({'training_loss': '{:.3f}'.format(loss.item()/len(batch))})


# saving the model after each epoch (name as per your choice)
torch.save(model.state_dict(), f'fine_tuned_bert/finetuned_BERT_epoch_{epoch}.model')

tqdm.write(f'\nEpoch {epoch}')
Expand Down
31 changes: 0 additions & 31 deletions django-backend/mlApi/data_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,6 @@

print(dark_pattern_counts3)

# Alternatively, you can use df.isnull().sum()

# Print or use the information about NaN values
# print(nan_values)

# print(uniqueVal1)
# print(uniqueVal3)

# new_df = df[['text', 'Pattern Category']]
# new_df.to_csv('F:/backup-kali/codeFiles/projects/cognigaurd/api/datasets/new_dp_dataset.csv',sep="\t", index=False)


# import pandas as pd

# output_file_path = "F:/backup-kali/codeFiles/projects/cognigaurd/api/datasets/new_dp_dataset.csv"

# # Read the TSV file
# df = pd.read_csv(file_path2, sep='\t')

# # Write the DataFrame to a CSV file
# df.to_csv(output_file_path, index=False)

# print("TSV file converted to CSV successfully!")

# df3 = pd.read_csv(output_file_path)
# dark_pattern_counts3 = df3['Category'].value_counts()
# print(dark_pattern_counts3)


##3 checking for incosistency in dataset


import csv

Expand Down
5 changes: 3 additions & 2 deletions django-backend/mlApi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Create your models here.


# beta feature - saving the transparency score to the database
class WebsiteTransparencyScore(models.Model):
website_name = models.CharField(max_length=255, unique=True)
transparency_score = models.FloatField()
Expand All @@ -12,7 +12,7 @@ class WebsiteTransparencyScore(models.Model):
def __str__(self):
return f"{self.website_name} - Transparency Score: {self.transparency_score}"


# saving dark pattern data to the database
class DarkPatternsData(models.Model):

website_url = models.URLField()
Expand All @@ -23,6 +23,7 @@ def __str__(self):
return f"{self.website_url} - Dark Pattern: {self.dark_pattern_label}"


# saving each request to the database
class DpRequest(models.Model):


Expand Down
2 changes: 1 addition & 1 deletion django-backend/mlApi/predict_darkp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def find_dark_pattern(text_predict):



# # text_to_predict = "Hello my name is adarsh and my friend name is aman , he is only on sale for the next two days. "
# # text_to_predict = "Hello my name is adarsh and my friend name is aman "
# welcomeMsg = """******* Welcome to Dark Pattern Detector ********"""

# text_to_predict = input("Enter the the text to find Dark Pattern : ")
Expand Down
2 changes: 2 additions & 0 deletions django-backend/mlApi/scrapingTerms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This script scrapes the terms and conditions of the websites mentioned in the 'websites' list and saves the data to a CSV file.

import requests
from bs4 import BeautifulSoup
import csv
Expand Down
14 changes: 7 additions & 7 deletions django-backend/mlApi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ class MessageListView(generics.ListAPIView):
## You need to ensure that it doesn't call the dpData function if the dpCond is False

# Fetching urls from model
# dpUrls = DpRequest.objects.all()
# urlLen = len(dpUrls)
# myDpUrl = dpUrls[urlLen-1].url
# print(dpUrls)
# myOutput = dpData(myDpUrl)
# print(myOutput)
# dpCond = False
dpUrls = DpRequest.objects.all()
urlLen = len(dpUrls)
myDpUrl = dpUrls[urlLen-1].url
print(dpUrls)
myOutput = dpData(myDpUrl)
print(myOutput)
dpCond = False



Expand Down
2 changes: 1 addition & 1 deletion django-backend/static/css/report.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
}
.content-section {
gap: 3rem;
padding-left: 30rem;
/* padding-left: 30rem; */
}
.heading-section {
display: flex;
Expand Down
85 changes: 14 additions & 71 deletions django-backend/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@
--font-large: 3rem;
--font-ex-large: 3.5rem;
}
@media (max-width: 768px) {
:root {
--font-ex-small: 0.25rem;
--font-small: 0.5rem;
--font-mid-medium: 1rem;
--font-medium: 1.25rem;
--font-mid-large: 1.75rem;
--font-large: 2rem;
}
}

a {
text-decoration: none;
}
Expand Down Expand Up @@ -110,22 +101,16 @@ a {
align-items: center;
gap: 5rem;
margin: 4rem 0;
@media (max-width: 768px) {
margin: 5vh 0 !important;
flex-direction: column;
gap: 3rem;
}

}
.blue-text {
color: var(--color-primary);
}
/* main section */
.main-section {
display: flex;
justify-content: center;
@media (max-width: 768px) {
flex-direction: column;
}
/* justify-content: center; */

/* gap: 2rem;
padding: 0 2.87rem; */
}
Expand All @@ -136,10 +121,7 @@ a {
align-items: center;
margin: 6rem 2rem 2rem 4rem;
gap: 8rem;
@media (max-width: 768px) {
margin: 10vh 10vw;
gap: 15vh;
}

}
/* navbar */
.navbar {
Expand All @@ -158,45 +140,20 @@ a {
background: white;
gap: 2rem;
height: 558px;
@media (max-width: 768px) {
flex-direction: row;
height: 100px;
padding: 0 5vw;
/*
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 100;
transform: translateX(-100%);
transition: 0.5s; */
}

}
.navbar__logo img {
height: 5.75rem;
width: 9.55rem;
@media (max-width: 768px) {
height: 5rem;
width: 8.5rem;
}

}
.navbar__links {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2rem;
width: 14rem;
@media (max-width: 768px) {
position: fixed;
z-index: 3;
background-color: white;
padding: 3vh 5vw;
border-radius: 10px;
right: -100vw;
top: 25vh;
border: 1px solid black;
transition: all 0.5s ease-in-out;
}

}
.show {
transform: translateX(-100vw);
Expand All @@ -217,9 +174,7 @@ a {
}
.welcome-img {
height: 40vh;
@media (max-width: 768px) {
height: 25vh;
}

}
.welcome-btns {
display: flex;
Expand All @@ -246,9 +201,7 @@ a {
}
.cogni-about img {
height: 50vh;
@media (max-width: 768px) {
height: 30vh;
}

}
/* footer */
footer {
Expand All @@ -275,11 +228,7 @@ footer {
color: white;
justify-content: space-evenly;
align-items: center;
@media (max-width: 768px) {
flex-direction: column;
align-items: flex-start;
gap: 10vh;
}

}
.footer-text a {
color: white;
Expand Down Expand Up @@ -310,9 +259,7 @@ footer {
width: 50%;
flex-direction: column;
gap: 1rem;
@media (max-width: 768px) {
width: auto;
}

}
.cogni-desc p {
letter-spacing: 0.5px;
Expand All @@ -323,9 +270,7 @@ footer {
display: flex;
flex-direction: column;
gap: 2rem;
@media (max-width: 768px) {
gap: 1.5rem;
}

}
.cogni-links div:first-child {
display: flex;
Expand Down Expand Up @@ -390,9 +335,7 @@ footer {
cursor: pointer;
padding: 0;
z-index: 10;
@media (max-width: 768px) {
display: flex;
}

}

.line {
Expand Down
File renamed without changes
Loading

0 comments on commit a5d2de6

Please sign in to comment.