Spaces:
Sleeping
Sleeping
Ali Abdullah
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, render_template_string, request, jsonify
|
| 2 |
import os
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from langchain_community.vectorstores import FAISS
|
|
@@ -202,17 +202,11 @@ def index():
|
|
| 202 |
margin-bottom: 1.5rem;
|
| 203 |
}
|
| 204 |
|
| 205 |
-
.logo-
|
| 206 |
-
width: 160px;
|
| 207 |
height: 48px;
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
align-items: center;
|
| 212 |
-
justify-content: center;
|
| 213 |
-
color: white;
|
| 214 |
-
font-weight: 700;
|
| 215 |
-
font-size: 18px;
|
| 216 |
}
|
| 217 |
|
| 218 |
.title-bubble {
|
|
@@ -600,7 +594,7 @@ def index():
|
|
| 600 |
<body>
|
| 601 |
<div class="header">
|
| 602 |
<div class="logo">
|
| 603 |
-
<img src="/static/atomcamp_logo.png" alt="Atomcamp Logo" class="logo-image" style="height:
|
| 604 |
</div>
|
| 605 |
|
| 606 |
<div class="title-bubble">
|
|
@@ -704,7 +698,7 @@ def index():
|
|
| 704 |
|
| 705 |
function updateCharCount() {
|
| 706 |
const count = messageInput.value.length;
|
| 707 |
-
charCount.textContent =
|
| 708 |
}
|
| 709 |
|
| 710 |
async function handleSubmit(e) {
|
|
@@ -748,13 +742,13 @@ def index():
|
|
| 748 |
}
|
| 749 |
|
| 750 |
const messageDiv = document.createElement('div');
|
| 751 |
-
messageDiv.className = message ${role}
|
| 752 |
|
| 753 |
const messageContent = document.createElement('div');
|
| 754 |
messageContent.className = 'message-content';
|
| 755 |
|
| 756 |
const avatar = document.createElement('div');
|
| 757 |
-
avatar.className = avatar ${role}
|
| 758 |
|
| 759 |
if (role === 'user') {
|
| 760 |
avatar.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>';
|
|
@@ -766,11 +760,11 @@ def index():
|
|
| 766 |
bubble.className = 'message-bubble';
|
| 767 |
|
| 768 |
if (role === 'user') {
|
| 769 |
-
bubble.innerHTML =
|
| 770 |
messageContent.appendChild(bubble);
|
| 771 |
messageContent.appendChild(avatar);
|
| 772 |
} else {
|
| 773 |
-
bubble.innerHTML =
|
| 774 |
messageContent.appendChild(avatar);
|
| 775 |
messageContent.appendChild(bubble);
|
| 776 |
}
|
|
@@ -785,20 +779,20 @@ def index():
|
|
| 785 |
function formatMessageContent(content) {
|
| 786 |
return content.split('\\n').map(line => {
|
| 787 |
if (line.trim().startsWith('•') || line.trim().startsWith('-')) {
|
| 788 |
-
return
|
| 789 |
<span style="color: #16a34a; margin-right: 0.5rem; margin-top: 0.125rem; font-size: 0.875rem; font-weight: 500;">•</span>
|
| 790 |
<span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^[•-]\\s*/, '')}</span>
|
| 791 |
-
</div
|
| 792 |
} else if (/^\\d+\\./.test(line.trim())) {
|
| 793 |
const match = line.match(/^\\d+\\./);
|
| 794 |
-
return
|
| 795 |
<span style="color: #16a34a; margin-right: 0.5rem; font-weight: 600; font-size: 0.875rem;">${match ? match[0] : ''}</span>
|
| 796 |
<span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^\\d+\\.\\s*/, '')}</span>
|
| 797 |
-
</div
|
| 798 |
} else if (line.trim() === '') {
|
| 799 |
return '<br>';
|
| 800 |
} else {
|
| 801 |
-
return
|
| 802 |
}
|
| 803 |
}).join('');
|
| 804 |
}
|
|
@@ -856,6 +850,10 @@ def chat():
|
|
| 856 |
except Exception as e:
|
| 857 |
return jsonify({'error': f'Error: {str(e)}'}), 500
|
| 858 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 859 |
# Initialize systems
|
| 860 |
initialize_groq()
|
| 861 |
initialize_vectorstore()
|
|
|
|
| 1 |
+
from flask import Flask, render_template_string, request, jsonify, send_from_directory
|
| 2 |
import os
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from langchain_community.vectorstores import FAISS
|
|
|
|
| 202 |
margin-bottom: 1.5rem;
|
| 203 |
}
|
| 204 |
|
| 205 |
+
.logo-img {
|
|
|
|
| 206 |
height: 48px;
|
| 207 |
+
width: auto;
|
| 208 |
+
object-fit: contain;
|
| 209 |
+
max-width: 200px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
}
|
| 211 |
|
| 212 |
.title-bubble {
|
|
|
|
| 594 |
<body>
|
| 595 |
<div class="header">
|
| 596 |
<div class="logo">
|
| 597 |
+
<img src="/static/atomcamp_logo.png" alt="Atomcamp Logo" class="logo-image" style="height: 42px;">
|
| 598 |
</div>
|
| 599 |
|
| 600 |
<div class="title-bubble">
|
|
|
|
| 698 |
|
| 699 |
function updateCharCount() {
|
| 700 |
const count = messageInput.value.length;
|
| 701 |
+
charCount.textContent = `${count}/1000`;
|
| 702 |
}
|
| 703 |
|
| 704 |
async function handleSubmit(e) {
|
|
|
|
| 742 |
}
|
| 743 |
|
| 744 |
const messageDiv = document.createElement('div');
|
| 745 |
+
messageDiv.className = `message ${role}`;
|
| 746 |
|
| 747 |
const messageContent = document.createElement('div');
|
| 748 |
messageContent.className = 'message-content';
|
| 749 |
|
| 750 |
const avatar = document.createElement('div');
|
| 751 |
+
avatar.className = `avatar ${role}`;
|
| 752 |
|
| 753 |
if (role === 'user') {
|
| 754 |
avatar.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>';
|
|
|
|
| 760 |
bubble.className = 'message-bubble';
|
| 761 |
|
| 762 |
if (role === 'user') {
|
| 763 |
+
bubble.innerHTML = `<div class="message-text">${content}</div>`;
|
| 764 |
messageContent.appendChild(bubble);
|
| 765 |
messageContent.appendChild(avatar);
|
| 766 |
} else {
|
| 767 |
+
bubble.innerHTML = `<div class="message-formatted">${formatMessageContent(content)}</div>`;
|
| 768 |
messageContent.appendChild(avatar);
|
| 769 |
messageContent.appendChild(bubble);
|
| 770 |
}
|
|
|
|
| 779 |
function formatMessageContent(content) {
|
| 780 |
return content.split('\\n').map(line => {
|
| 781 |
if (line.trim().startsWith('•') || line.trim().startsWith('-')) {
|
| 782 |
+
return `<div style="display: flex; align-items: flex-start; margin-bottom: 0.375rem;">
|
| 783 |
<span style="color: #16a34a; margin-right: 0.5rem; margin-top: 0.125rem; font-size: 0.875rem; font-weight: 500;">•</span>
|
| 784 |
<span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^[•-]\\s*/, '')}</span>
|
| 785 |
+
</div>`;
|
| 786 |
} else if (/^\\d+\\./.test(line.trim())) {
|
| 787 |
const match = line.match(/^\\d+\\./);
|
| 788 |
+
return `<div style="display: flex; align-items: flex-start; margin-bottom: 0.375rem;">
|
| 789 |
<span style="color: #16a34a; margin-right: 0.5rem; font-weight: 600; font-size: 0.875rem;">${match ? match[0] : ''}</span>
|
| 790 |
<span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^\\d+\\.\\s*/, '')}</span>
|
| 791 |
+
</div>`;
|
| 792 |
} else if (line.trim() === '') {
|
| 793 |
return '<br>';
|
| 794 |
} else {
|
| 795 |
+
return `<p style="margin-bottom: 0.375rem; font-size: 0.875rem; line-height: 1.5;">${line}</p>`;
|
| 796 |
}
|
| 797 |
}).join('');
|
| 798 |
}
|
|
|
|
| 850 |
except Exception as e:
|
| 851 |
return jsonify({'error': f'Error: {str(e)}'}), 500
|
| 852 |
|
| 853 |
+
@app.route('/static/<path:filename>')
|
| 854 |
+
def static_files(filename):
|
| 855 |
+
return send_from_directory('static', filename)
|
| 856 |
+
|
| 857 |
# Initialize systems
|
| 858 |
initialize_groq()
|
| 859 |
initialize_vectorstore()
|