Skip to content

Commit

Permalink
yes
Browse files Browse the repository at this point in the history
  • Loading branch information
mukulpatnaik committed Feb 7, 2023
1 parent 43ee5c4 commit d72f28c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# from google.cloud import storage

app = Flask(__name__)
db=redis.from_url(os.environ['REDISCLOUD_URL'])
# db = redis.StrictRedis(host='localhost', port=6379, db=0)
# db=redis.from_url(os.environ['REDISCLOUD_URL'])
db = redis.StrictRedis(host='localhost', port=6379, db=0)
CORS(app)


Expand Down
28 changes: 25 additions & 3 deletions static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const input = document.querySelector("input[type='file']");
const uploadBtn = document.querySelector(".upload-btn");
const viewer = document.querySelector("#pdf-viewer");
const container = document.querySelector("#container");
const x = document.querySelector("input[name='pdf-url']");
var x = document.querySelector("input[name='pdf-url']");
const form = document.querySelector("form");
const p = document.querySelector("p");
const up = document.querySelector("#up");
Expand All @@ -24,6 +24,12 @@ send.addEventListener("click", function(event) {
const query = document.createElement("p");
query.innerHTML = message;
chat.appendChild(query);

const loading = document.createElement("p");
loading.style.color = "lightgray";
loading.style.fontSize = "14px";
loading.innerHTML = "Loading...";
chat.appendChild(loading);

// call the endpoint /reply with the message and get the reply.
fetch('/reply', {
Expand All @@ -36,7 +42,8 @@ send.addEventListener("click", function(event) {
.then(response => response.json())
// Append the reply to #chat as a simple paragraph without any styling
.then(data => {
console.log(data.answer)
console.log(data.answer);
chat.removeChild(loading);

const reply = document.createElement("p");
reply.style.color = "lightgray";
Expand Down Expand Up @@ -78,8 +85,8 @@ x.addEventListener("focus", function() {

y.addEventListener("submit", function(event) {
event.preventDefault();

const url = this.elements["pdf-url"].value;
x.value = "Loading...";
console.log(url);
fetch('https://api.codetabs.com/v1/proxy?quest='+url)
.then(response => response.blob())
Expand All @@ -100,6 +107,12 @@ y.addEventListener("submit", function(event) {
.catch(error => {
console.error(error);
});
var loading = document.createElement("p");
loading.style.color = "lightgray";
loading.style.fontSize = "14px";
loading.innerHTML = "Calculating embeddings...";
chat.appendChild(loading);

// Make a POST request to the server 'myserver/download-pdf' with the URL
fetch('/download_pdf', {
method: 'POST',
Expand All @@ -114,6 +127,7 @@ y.addEventListener("submit", function(event) {
.then(response => response.json())
// Append the reply to #chat as a simple paragraph without any styling
.then(data => {
chat.removeChild(loading);
window.key = data.key;
});

Expand All @@ -123,6 +137,13 @@ input.addEventListener("change", async function() {
const file = this.files[0];
const fileArrayBuffer = await file.arrayBuffer();
console.log(fileArrayBuffer);

var loading = document.createElement("p");
loading.style.color = "lightgray";
loading.style.fontSize = "14px";
loading.innerHTML = "Calculating embeddings...";
chat.appendChild(loading);

// Make a post request to /process_pdf with the file
fetch('/process_pdf', {
method: 'POST',
Expand All @@ -138,6 +159,7 @@ input.addEventListener("change", async function() {
.then(response => response.json())
// Append the reply to #chat as a simple paragraph without any styling
.then(data => {
chat.removeChild(loading);
window.key = data.key;
});
pdfjsLib.getDocument(fileArrayBuffer).promise.then(pdfDoc => {
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<!-- Chat messages go here -->
</div>
<form style="display: flex; padding-left: 10px; margin-bottom: 10px; width: 100%;">
<input type="text" name='chat' style="font-size: 14px; flex-grow: 2; padding: 10px; border: none; background-color: black; color: white;" placeholder="Type a message..." />
<input type="text" name='chat' style="font-size: 14px; flex-grow: 2; padding: 10px; border: none; background-color: black; color: white;" placeholder="Ask a question..." />
<button id="send" style="background-color: transparent; border: none; padding: 10px 20px;">
<img src="static/send-icon.png" style="width: 20px; height: 20px;" />
</button>
Expand Down

0 comments on commit d72f28c

Please sign in to comment.