Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,12 @@ import logging
|
|
4 |
from typing import List, Dict
|
5 |
import torch
|
6 |
import gradio as gr
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
10 |
from langchain.chains import RetrievalQA
|
11 |
from langchain.prompts import PromptTemplate
|
12 |
-
from
|
13 |
from langchain_community.document_loaders import PyPDFLoader, TextLoader, Docx2txtLoader
|
14 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
15 |
|
@@ -246,46 +246,36 @@ def process_query(message, history):
|
|
246 |
return history + [(message, f"Error: {str(e)}")]
|
247 |
|
248 |
# Create Gradio interface
|
249 |
-
|
250 |
-
div.gradio-container {background-color: #f0f2f6}
|
251 |
-
div.upload-box {
|
252 |
-
border: 2px dashed #ccc;
|
253 |
-
padding: 20px;
|
254 |
-
border-radius: 10px;
|
255 |
-
background-color: #ffffff;
|
256 |
-
margin-bottom: 15px;
|
257 |
-
}
|
258 |
-
""")
|
259 |
-
|
260 |
-
with demo:
|
261 |
gr.HTML("""
|
262 |
-
<div style="text-align: center;
|
263 |
<h1 style="color: #2d333a;">π€ Easy RAG</h1>
|
264 |
-
<p style="color: #4a5568;">
|
265 |
-
A simple and powerful RAG system for your documents
|
266 |
-
</p>
|
267 |
</div>
|
268 |
""")
|
269 |
|
270 |
with gr.Row():
|
271 |
# Sidebar for document upload
|
272 |
with gr.Column(scale=1):
|
273 |
-
with gr.Box(
|
274 |
gr.HTML("<h3>π Document Upload</h3>")
|
275 |
file_output = gr.File(
|
276 |
file_count="multiple",
|
277 |
-
label="Upload Documents
|
278 |
-
|
279 |
)
|
280 |
gr.HTML("""
|
281 |
<div style="font-size: 0.8em; color: #666;">
|
282 |
<p>β’ Maximum 5 files</p>
|
283 |
<p>β’ 10MB per file</p>
|
284 |
-
<p>β’ Supported
|
285 |
</div>
|
286 |
""")
|
287 |
upload_button = gr.Button("π€ Upload and Initialize", variant="primary")
|
288 |
-
system_output = gr.Textbox(
|
|
|
|
|
|
|
289 |
|
290 |
# Main chat area
|
291 |
with gr.Column(scale=3):
|
@@ -303,24 +293,24 @@ with demo:
|
|
303 |
container=False,
|
304 |
scale=8
|
305 |
)
|
306 |
-
clear = gr.Button("ποΈ
|
307 |
|
308 |
gr.HTML("""
|
309 |
-
<div style="text-align: center; max-width: 800px; margin: 20px auto; padding:
|
310 |
background-color: #f8f9fa; border-radius: 10px;">
|
311 |
-
<div style="margin-bottom:
|
312 |
<h3 style="color: #2d333a;">π About Easy RAG</h3>
|
313 |
-
<p style="color: #666; font-size:
|
314 |
-
|
315 |
</p>
|
316 |
-
<ul style="list-style: none; color: #666; font-size:
|
317 |
<li>πΉ LLM: Llama-2-7b-chat-hf</li>
|
318 |
<li>πΉ Embeddings: multilingual-e5-large</li>
|
319 |
<li>πΉ Vector Store: FAISS</li>
|
320 |
</ul>
|
321 |
</div>
|
322 |
-
<div style="border-top: 1px solid #ddd; padding-top:
|
323 |
-
<p style="color: #666; font-size:
|
324 |
Based on original work by <a href="https://www.linkedin.com/in/camilo-vega-169084b1/"
|
325 |
target="_blank" style="color: #2196F3; text-decoration: none;">Camilo Vega</a>
|
326 |
</p>
|
@@ -343,4 +333,5 @@ with demo:
|
|
343 |
|
344 |
clear.click(lambda: None, None, chatbot)
|
345 |
|
346 |
-
|
|
|
|
4 |
from typing import List, Dict
|
5 |
import torch
|
6 |
import gradio as gr
|
7 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
8 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
9 |
+
from langchain_community.vectorstores import FAISS
|
10 |
from langchain.chains import RetrievalQA
|
11 |
from langchain.prompts import PromptTemplate
|
12 |
+
from langchain_community.llms import HuggingFacePipeline
|
13 |
from langchain_community.document_loaders import PyPDFLoader, TextLoader, Docx2txtLoader
|
14 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
15 |
|
|
|
246 |
return history + [(message, f"Error: {str(e)}")]
|
247 |
|
248 |
# Create Gradio interface
|
249 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
gr.HTML("""
|
251 |
+
<div style="text-align: center; margin-bottom: 1rem;">
|
252 |
<h1 style="color: #2d333a;">π€ Easy RAG</h1>
|
253 |
+
<p style="color: #4a5568;">A simple and powerful RAG system for your documents</p>
|
|
|
|
|
254 |
</div>
|
255 |
""")
|
256 |
|
257 |
with gr.Row():
|
258 |
# Sidebar for document upload
|
259 |
with gr.Column(scale=1):
|
260 |
+
with gr.Box():
|
261 |
gr.HTML("<h3>π Document Upload</h3>")
|
262 |
file_output = gr.File(
|
263 |
file_count="multiple",
|
264 |
+
label="Upload Documents",
|
265 |
+
elem_id="file-upload"
|
266 |
)
|
267 |
gr.HTML("""
|
268 |
<div style="font-size: 0.8em; color: #666;">
|
269 |
<p>β’ Maximum 5 files</p>
|
270 |
<p>β’ 10MB per file</p>
|
271 |
+
<p>β’ Supported: PDF, TXT, DOCX</p>
|
272 |
</div>
|
273 |
""")
|
274 |
upload_button = gr.Button("π€ Upload and Initialize", variant="primary")
|
275 |
+
system_output = gr.Textbox(
|
276 |
+
label="System Status",
|
277 |
+
interactive=False
|
278 |
+
)
|
279 |
|
280 |
# Main chat area
|
281 |
with gr.Column(scale=3):
|
|
|
293 |
container=False,
|
294 |
scale=8
|
295 |
)
|
296 |
+
clear = gr.Button("ποΈ", size="sm", scale=1)
|
297 |
|
298 |
gr.HTML("""
|
299 |
+
<div style="text-align: center; max-width: 800px; margin: 20px auto; padding: 1rem;
|
300 |
background-color: #f8f9fa; border-radius: 10px;">
|
301 |
+
<div style="margin-bottom: 1rem;">
|
302 |
<h3 style="color: #2d333a;">π About Easy RAG</h3>
|
303 |
+
<p style="color: #666; font-size: 0.9em;">
|
304 |
+
Powered by state-of-the-art AI technology:
|
305 |
</p>
|
306 |
+
<ul style="list-style: none; color: #666; font-size: 0.9em;">
|
307 |
<li>πΉ LLM: Llama-2-7b-chat-hf</li>
|
308 |
<li>πΉ Embeddings: multilingual-e5-large</li>
|
309 |
<li>πΉ Vector Store: FAISS</li>
|
310 |
</ul>
|
311 |
</div>
|
312 |
+
<div style="border-top: 1px solid #ddd; padding-top: 1rem;">
|
313 |
+
<p style="color: #666; font-size: 0.8em;">
|
314 |
Based on original work by <a href="https://www.linkedin.com/in/camilo-vega-169084b1/"
|
315 |
target="_blank" style="color: #2196F3; text-decoration: none;">Camilo Vega</a>
|
316 |
</p>
|
|
|
333 |
|
334 |
clear.click(lambda: None, None, chatbot)
|
335 |
|
336 |
+
if __name__ == "__main__":
|
337 |
+
demo.launch()
|