Skip to content

Commit

Permalink
updating datasets for balacing
Browse files Browse the repository at this point in the history
  • Loading branch information
4darsh-Dev committed Feb 14, 2024
1 parent 6066092 commit 647dede
Show file tree
Hide file tree
Showing 8 changed files with 2,398 additions and 21 deletions.
2,313 changes: 2,313 additions & 0 deletions api/datasets/new_dp_dataset_final.tsv

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions api/home/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Register your models here.

from .models import DarkPatternReport
from .models import DarkPatternReport, FAQData

admin.site.register(DarkPatternReport)
admin.site.register(FAQData)

admin.site.register(DarkPatternReport)
16 changes: 16 additions & 0 deletions api/home/faqs_save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Saving the data to models.py from csv file as input

import pandas as pd
from home.models import FAQData

def save_from_csv(file_path):
# Read the CSV file into a DataFrame
faq_df = pd.read_csv(file_path)

# Iterate over each row and save to FAQData model
for index, row in faq_df.iterrows():
FAQData.objects.create(question=row['question'], answer=row['answer'])

if __name__ == "__main__":
file_path = "faqs.csv"
save_from_csv(file_path)
21 changes: 21 additions & 0 deletions api/home/migrations/0002_faqdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.1 on 2024-02-13 06:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('home', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='FAQData',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question', models.CharField(max_length=200)),
('answer', models.TextField()),
],
),
]
6 changes: 6 additions & 0 deletions api/home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ class DarkPatternReport(models.Model):
def __str__(self):
return f"{self.name} - {self.website_name} "

class FAQData(models.Model):
question = models.CharField(max_length=200)
answer = models.TextField()

def __str__(self):
return self.question
10 changes: 8 additions & 2 deletions api/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
import base64
from PIL import Image

from .models import DarkPatternReport
from .models import DarkPatternReport,FAQData
from django.contrib import messages

# Create your views here.

import pandas as pd

def index(request):
return render(request, "index.html")


def faqs(request):
return render(request, "faqs.html")
faqs = FAQData.objects.all()
return render(request, "faqs.html", {"faqs": faqs})


def termsConditions(request):
return render(request, "termsConditions.html")
Expand Down Expand Up @@ -97,3 +100,6 @@ def reportDp(request):

return render(request, "report.html")




32 changes: 22 additions & 10 deletions api/mlApi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,35 @@
import pandas as pd
file_path = "F:/backup-kali/codeFiles/projects/cognigaurd/api/datasets/dp_dataset.tsv"

file_path2 = "F:/backup-kali/codeFiles/projects/cognigaurd/api/datasets/new_dp_dataset_final.tsv"

df = pd.read_csv(file_path, sep='\t')

uniqueVal1 = df['Pattern Category'].unique()
uniqueVal2 = df['text'].unique()
uniqueVal3 = df['label'].unique()
df2 = pd.read_csv(file_path2, sep='\t')

# uniqueVal2 = df['Pattern Category'].nunique()
# print(uniqueVal2)

# # Check for NaN values in the entire DataFrame
# nan_values = df.isna().sum()

dark_pattern_counts = df['Pattern Category'].value_counts()

dark_pattern_counts2 = df2['Pattern Category'].value_counts()



print(dark_pattern_counts)

# Check for NaN values in the entire DataFrame
nan_values = df.isna().sum()
print(dark_pattern_counts2)

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

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

print(uniqueVal1)
print(uniqueVal3)
# 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)
# 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)
15 changes: 8 additions & 7 deletions api/templates/faqs.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ <h2 class="font-medium">Clarity beyond Words</h2>
<h1 class="font-medium font-secondary">FAQs</h1>
<div class="faqs">
<div class="faqs-div">
{% if faqs %}

<div class="faq">
<div class="faq-question">
<span class="material-symbols-outlined">adjust</span>
<span class="faq-ques-text">What is Cogniguard?</span>
<span class="faq-ques-text">{{ faqs.question }}</span>
<i class="material-symbols-outlined faq-button">expand_more</i>
</div>
<div class="faq-answer hide" id="faq1-content">
<p>Cogniguard is a sophisticated web extension designed to amplify online transparency. It
provides users with a transparency score for visited websites, detecting and alerting users
about the presence of dark patterns. This empowers users to make informed decisions and
protect their privacy.</p>
<p> {{ faqs.answer}} </p>
</div>
</div>

<div class="faq">
{% endif %}

{% comment %} <div class="faq">
<div class="faq-question">
<span class="material-symbols-outlined">adjust</span>
<span class="faq-ques-text"> How does Cogniguard work?</span>
Expand Down Expand Up @@ -143,7 +144,7 @@ <h1 class="font-medium font-secondary">FAQs</h1>
"Cogniguard," and follow the installation instructions. Once installed, the extension will
work seamlessly in the background to enhance your browsing experience.</p>
</div>
</div>
</div> {% endcomment %}
</div>
</div>
</section>
Expand Down

0 comments on commit 647dede

Please sign in to comment.