Skip to content

Commit

Permalink
Model 1
Browse files Browse the repository at this point in the history
  • Loading branch information
athiya26 authored Mar 15, 2024
1 parent be1b256 commit 00dd2a2
Show file tree
Hide file tree
Showing 8 changed files with 1,893 additions and 0 deletions.
Binary file modified README.md
Binary file not shown.
1,617 changes: 1,617 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"dependencies": {
"dotenv": "^16.4.1",
"express": "^4.18.2",
"openai": "^4.27.0"
},
"scripts": {
"start": "node server.js"
},
"name": "gpt-sentiment-rater",
"version": "1.0.0",
"main": "server.js",
"devDependencies": {},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
Binary file added public/assets/smare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>SMARE Car Listing Analysis</title>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
</head>

<body>
<header>
<img src="assets/smare.png" class="logo" alt="SMARE Logo">
<h1>Social Marketplace Automotive Risk Engine</h1>
<p>Calculating Automotive Risk On online Social Media Marketplaces.</p>
<nav>
<!-- Add your navigation items if needed -->
</nav>
</header>

<main>
<form id="carListingForm">
<input type="text" id="make" placeholder="Car Make">
<input type="text" id="model" placeholder="Car Model">
<input type="number" id="year" placeholder="Year">
<input type="number" id="mileage" placeholder="Mileage">
<input type="number" id="imageCount" placeholder="Number of Images">
<input type="number" id="listingPrice" placeholder="Listing Price">
<button type="button" id="analyzeButton">Analyze Listing</button>
<button type="button" id="checkPriceButton">Check KBB Price</button>
</form>

<div id="analysisResult">
<h3>Analysis Result:</h3>
<div id="analysisContent" class="response"></div>
</div>

<div id="loadingSpinner" class="spinner" style="display: none;"></div>
</main>

<footer>
<p>Powered by OpenAI</p>
</footer>

<script src="script.js"></script>
</body>

</html>
72 changes: 72 additions & 0 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
document.addEventListener('DOMContentLoaded', function () {
// Initialize form input variables
const carMake = document.getElementById('make');
const carModel = document.getElementById('model');
const carYear = document.getElementById('year');
const carMileage = document.getElementById('mileage');
const imageCount = document.getElementById('imageCount');
const listingPrice = document.getElementById('listingPrice');
const analysisResult = document.getElementById('analysisResult');
const analysisContent = document.getElementById('analysisContent');

// Function to construct the ChatGPT prompt
function constructPrompt(kbbPrice) {
return `Analyze the legitimacy of this car listing based on the following details: Make: ${carMake.value}, Model: ${carModel.value}, Year: ${carYear.value}, Mileage: ${carMileage.value}, Number of Images: ${imageCount.value}, Listing Price: ${listingPrice.value}, Kelley Blue Book Price: ${kbbPrice}. Provide a detailed explanation and a legitimacy score from 0 to 10.`;
}

function showLoadingSpinner() {
document.getElementById('loadingSpinner').style.display = 'block';
}

// Function to hide the loading spinner
function hideLoadingSpinner() {
document.getElementById('loadingSpinner').style.display = 'none';
}

async function fetchKBBPrice(make, model, year) {
try {
const response = await fetch(`http://localhost:5000/get_price?make=${make}&model=${model}&year=${year}`);
const data = await response.json();
console.log(data);
return data.price;
} catch (error) {
console.error("Error fetching KBB price:", error);
return null;
}
}

// Function to handle the analyze button click
document.getElementById('analyzeButton').addEventListener('click', async function () {
showLoadingSpinner();
let kbbPrice = await fetchKBBPrice(carMake.value, carModel.value, carYear.value);
let prompt = constructPrompt(kbbPrice);

let response = await fetch('/chatGPT', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ messages: [{ role: "system", content: "The following task requires an analysis of automotive listings. The user will input details about a car's make, model, year, mileage, number of images from the posting, and the current listing price as shown on a social media marketplace. Your job is to use this information to assess whether the listing seems reasonable, overpriced, or potentially a scam. Consider factors such as the car's used market value, which is found through kelley blue book using a python webscraper, and common indicators of scams. Provide a detailed explanation of your assessment, including any red flags or positive indicators you identify. Finally, assign a legitimacy score from 0 to 10, with decimals allowed, where 10 signifies a highly legitimate listing and 0 indicates a high probability of being a scam. Your analysis will help the user make an informed decision about the listing." }, { role: "user", content: prompt }] })
});
let aiData = await response.json();
hideLoadingSpinner();
displayAnalysisResult(aiData, kbbPrice);
});

document.getElementById('checkPriceButton').addEventListener('click', async function () {
showLoadingSpinner();
let kbbPrice = await fetchKBBPrice(carMake.value, carModel.value, carYear.value);

if (kbbPrice !== null) {
analysisContent.innerHTML = `Kelley Blue Book Price: ${kbbPrice}`;
} else {
analysisContent.innerHTML = `Price could not be fetched from Kelley Blue Book.`;
}
analysisResult.style.display = 'block';
hideLoadingSpinner();
});

// Function to display the analysis result
function displayAnalysisResult(aiData, kbbPrice) {
analysisContent.innerHTML = `Kelley Blue Book Price: ${kbbPrice}<br>AI Analysis: ${aiData.choices[0].message.content}`;
analysisResult.style.display = 'block';
}
});
109 changes: 109 additions & 0 deletions public/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
body {
font-family: 'Helvetica Neue', Arial, sans-serif;
margin: 0;
background-color: #f4f4f4;
color: #666;
}

header {
background-color: #fff;
padding: 20px 0;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
text-align: center;
}

header h1 {
margin: 0;
color: #f01716;
}

header p {
color: #666;
}

main {
width: 80%;
margin: 20px auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}

#carListingForm {
display: flex;
flex-direction: column;
gap: 15px;
}

#carListingForm input[type='text'],
#carListingForm input[type='number'] {
padding: 10px;
border: 2px solid #ddd;
border-radius: 4px;
font-size: 16px;
}

#analyzeButton,
#checkPriceButton {
padding: 12px 20px;
background-color: #f01716;
color: white;
border: none;
border-radius: 4px;
font-weight: bold;
font-size: 18px;
cursor: pointer;
transition: background-color 0.3s ease;
}

#analyzeButton:hover {
background-color: #a9060c;
}

#analysisResult {
margin-top: 30px;
padding: 20px;
background-color: #fff;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

footer {
background-color: #fff;
text-align: center;
padding: 10px 0;
bottom: 0;
width: 100%;
box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}

/* Add this class for your logo image in the header */
.logo {
display: block;
margin: 0 auto;
max-width: 200px;
/* Set the maximum width you desire */
height: auto;
/* This will maintain the aspect ratio */
}

.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #f01716;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin-top: 30px;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(360deg);
}
}
29 changes: 29 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require('dotenv').config();
const express = require('express');
const { OpenAI } = require("openai");
const app = express();
const port = 3000;

app.use(express.static('public'));
app.use(express.json());

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

app.post('/chatGPT', async (req, res) => {
try {
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: req.body.messages
});
return res.json(response);
} catch (error) {
console.error(error);
res.status(500).send('Error in OpenAI request');
}
});

app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});

1 comment on commit 00dd2a2

@vercel
Copy link

@vercel vercel bot commented on 00dd2a2 Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

seniordesign – ./

seniordesign-lryanle.vercel.app
seniordesign-git-main-lryanle.vercel.app
smare.vercel.app
smare.lryanle.com

Please sign in to comment.