Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions Algolyzer/playground/templates/playground/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<h1 class="text-center my-10 font-bold font-poppins text-5xl">Playground</h1>
<h1 class="font-bold text-xl mb-5">Pre-Trained AIML Models</h1>

{% comment %} Sentiment Analysis {% endcomment %}
<div class="flex flex-col gap-5">

{% comment %} Sentiment Analysis {% endcomment %}
<div class="rounded-xl border-2 border-solid border-primary p-5 hover:border-secondary">
<div class="flex md:items-center justify-between md:flex-row flex-col">
<h1 class="text-4xl my-2 p-4 text-primary">Sentiment Analysis</h1>
Expand Down Expand Up @@ -59,6 +59,57 @@ <h1 class="text-4xl my-2 p-4 text-primary">Sentiment Analysis</h1>
</div>
</div>


{% comment %} Linear Regression {% endcomment %}
<div class="rounded-xl border-2 border-solid border-primary p-5 hover:border-secondary">
<div class="flex md:items-center justify-between md:flex-row flex-col">
<h1 class="text-4xl my-2 p-4 text-primary">Linear Regression</h1>
<div class="flex gap-4">
<a href="{% url "linear_regression" %}" class="btn btn-accent font-bold font-poppins max-md:flex-1">Try Now</a>
<a href="#" class="btn btn-primary btn-outline max-md:flex-1">Learn More</a>
</div>
</div>
<div class="flex flex-col md:flex-row gap-4">
{% comment %} Left Segment {% endcomment %}
<div>
<div class="stats shadow max-w-lg">
<div class="stat">
<div class="stat-title">Accuracy</div>
<div class="stat-value text-primary">75%</div>
<div class="stat-desc">↗︎ 400 (22%)</div>
</div>

<div class="stat">
<div class="stat-title">Ratings</div>
<div class="stat-value">
<form class="rating rating-md rating-half">
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-1 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-2 bg-yellow-400" disabled/>
<input
type="radio"
name="rating-10"
class="mask mask-star-2 mask-half-1 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-2 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-1 bg-yellow-400" checked="checked" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-2 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-1 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-2 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-1 bg-yellow-400" disabled/>
<input type="radio" name="rating-10" class="mask mask-star-2 mask-half-2 bg-yellow-400" disabled/>
</form>
</div>
<div class="stat-desc">↘︎ 90 (14%)</div>
</div>
</div>
</div>

{% comment %} Right Segment {% endcomment %}
<div>
<p>{% lorem 1 b random %}
</p>
</div>
</div>
</div>
{% comment %} Doodle Classifier {% endcomment %}
<div class="rounded-xl border-2 border-solid border-primary p-5 hover:border-secondary">
<div class="flex md:items-center justify-between md:flex-row flex-col">
Expand Down Expand Up @@ -101,7 +152,7 @@ <h1 class="text-4xl my-2 p-4 text-primary">Doodle Classifier</h1>
</div>
</div>
</div>

{% comment %} Right Segment {% endcomment %}
<div>
<p>{% lorem 1 b random %}
Expand Down
128 changes: 128 additions & 0 deletions Algolyzer/playground/templates/playground/linear_regression.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{% extends "base.html" %}

{% block extra_head %}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
{% endblock %}

{% block content %}
<div class="max-w-5xl mx-auto my-5 p-2 bg-base-200 shadow-lg ">
<div class="p-2 lg:p-5 rounded-xl border-2 border-solid border-primary">
<h1 class="text-4xl font-bold text-center my-5">Linear Regression</h1>


<form method="POST" class="space-y-4">
{% csrf_token %}
<label class="block text-lg font-semibold px-4">Enter values:</label>

{% for i in "12345" %}
<div class="px-4">
<label class="label">
<span class="label-text">Value {{ forloop.counter }}</span>
<span class="label-text-alt" id="slider-value-{{ forloop.counter }}">5</span>
</label>
<input
type="range"
name="value_{{ forloop.counter }}"
min="0"
max="10"
value="5"
class="range range-primary"
oninput="document.getElementById('slider-value-{{ forloop.counter }}').textContent = this.value"
/>
</div>
{% endfor %}

<button class="btn btn-primary w-full">Submit</button>
</form>

{% if predicted_value %}
<div class="px-4 py-4">
<div class="alert alert-info">
<p><strong>Input Values:</strong> {{ input_values|join:", " }}</p>
<p><strong>Prediction:</strong> The next value is {{ predicted_value }}.</p>
</div>
</div>
{% endif %}

{% if show_chart %}
<div class="px-4 py-4">
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title">Linear Regression Chart</h2>
<canvas id="regressionChart"></canvas>
</div>
</div>
</div>

{% block scripts %}
<script>
// Prepare data for Chart.js
const inputValues = {{ input_values|safe }};
const predictedValue = {{ predicted_value|safe }};
const slope = {{ slope|safe }};
const intercept = {{ intercept|safe }};

// Data points (indices 1 to 5 for inputs, 6 for prediction)
const dataPoints = inputValues.map((val, idx) => ({
x: idx + 1,
y: val
})).concat([{ x: 6, y: predictedValue }]);

// Regression line points (extend slightly for visibility)
const linePoints = [
{ x: 0.5, y: intercept + 0.5 * slope },
{ x: 6.5, y: intercept + 6.5 * slope }
];

// Initialize Chart.js
const ctx = document.getElementById('regressionChart').getContext('2d');
new Chart(ctx, {
type: 'scatter',
data: {
datasets: [
{
label: 'Data Points',
data: dataPoints,
backgroundColor: 'rgb(59, 130, 246)', // DaisyUI primary color
borderColor: 'rgb(59, 130, 246)',
showLine: false,
pointRadius: 6
},
{
label: 'Regression Line',
data: linePoints,
type: 'line',
borderColor: 'rgb(239, 68, 68)', // Contrast color (red)
backgroundColor: 'transparent',
fill: false,
pointRadius: 0,
borderWidth: 2
}
]
},
options: {
responsive: true,
scales: {
x: {
title: { display: true, text: 'Index' },
min: 0,
max: 7
},
y: {
title: { display: true, text: 'Value' },
min: 0,
max: 12
}
},
plugins: {
legend: { display: true }
}
}
});
</script>
{% endblock %}
{% endif %}

</div>
</div>
{% endblock %}
8 changes: 7 additions & 1 deletion Algolyzer/playground/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from django.urls import path

from .views import doodle_classifier, playground_home, sentiment_analysis
from .views import (
doodle_classifier,
linear_regression,
playground_home,
sentiment_analysis,
)

urlpatterns = [
path("", playground_home, name="playground_home"),
path("linear_regression", linear_regression, name="linear_regression"),
path("sentiment_analysis/", sentiment_analysis, name="sentiment_analysis"),
path("doodle_classifier/", doodle_classifier, name="doodle_classifier"),
]
47 changes: 47 additions & 0 deletions Algolyzer/playground/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import json
import os

import numpy as np
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.files.base import ContentFile
from django.shortcuts import redirect, render
from django.utils.timezone import now
from home.decorators import profile_required
from PIL import Image
from sklearn.linear_model import LinearRegression
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline

from .models import PlaygroundTask
Expand Down Expand Up @@ -159,3 +161,48 @@ def doodle_classifier(request):

context = {"previous_results": previous_results}
return render(request, "playground/doodle_classifier.html", context=context)


@login_required
def linear_regression(request):
if request.method == "POST":
# Collect form data (values from 5 sliders)
values = [
float(request.POST.get("value_1", 0)),
float(request.POST.get("value_2", 0)),
float(request.POST.get("value_3", 0)),
float(request.POST.get("value_4", 0)),
float(request.POST.get("value_5", 0)),
]

# Prepare data for linear regression
X = np.array(range(1, 6)).reshape(-1, 1) # Indices 1 to 5
y = np.array(values) # Slider values

# Train linear regression model
model = LinearRegression()
model.fit(X, y)

# Predict the next value (for index 6)
next_index = np.array([[6]])
predicted_value = model.predict(next_index)[0]

# Get regression line parameters for plotting
slope = model.coef_[0]
intercept = model.intercept_

# Pass data to template
return render(
request,
"playground/linear_regression.html",
{
"predicted_value": round(predicted_value, 2),
"input_values": values,
"slope": slope,
"intercept": intercept,
"show_chart": True, # Flag to display chart
},
)

else:
return render(request, "playground/linear_regression.html")
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ identify==2.6.4
idna==3.10
isort==5.13.2
Jinja2==3.1.5
joblib==1.4.2
keras==3.8.0
kombu==5.4.2
libclang==18.1.1
Expand All @@ -58,7 +59,6 @@ nvidia-curand-cu12==10.3.5.147
nvidia-cusolver-cu12==11.6.1.9
nvidia-cusparse-cu12==12.3.1.170
nvidia-cusparselt-cu12==0.6.2
nvidia-nccl-cu12==2.21.5
nvidia-nvjitlink-cu12==12.4.127
nvidia-nvtx-cu12==12.4.127
opt_einsum==3.4.0
Expand All @@ -83,22 +83,25 @@ regex==2024.11.6
requests==2.32.3
rich==13.9.4
safetensors==0.5.2
scikit-learn==1.6.1
scipy==1.15.2
setuptools==75.8.0
six==1.17.0
sqlparse==0.5.3
sympy==1.13.1
tensorboard==2.18.0
tensorboard-data-server==0.7.2
tensorflow==2.18.0
tensorflow_intel==2.18.0
termcolor==2.5.0
tf_keras==2.18.0
threadpoolctl==3.6.0
tokenizers==0.21.0
torch==2.6.0
torchaudio==2.6.0
torchvision==0.21.0
tqdm==4.67.1
transformers==4.48.3
triton==3.2.0
typing_extensions==4.12.2
tzdata==2025.1
urllib3==2.3.0
Expand Down
Loading