Spaces:
Runtime error
Runtime error
Upload 8 files
Browse files- NEYIRE/README.md +12 -0
- NEYIRE/app.py +87 -0
- NEYIRE/assets/style.css +39 -0
- NEYIRE/modules/code_assistant.py +23 -0
- NEYIRE/modules/docs_assistant.py +32 -0
- NEYIRE/modules/pdf_assistant.py +36 -0
- NEYIRE/modules/utils.py +1 -0
- NEYIRE/requirements.txt +6 -0
NEYIRE/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Enterprise RAG Assistant
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 4.0.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
python_version: "3.10"
|
11 |
+
app_port: 7860
|
12 |
+
|
NEYIRE/app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from modules.code_assistant import CodeAssistant
|
3 |
+
from modules.docs_assistant import DocsAssistant
|
4 |
+
from modules.pdf_assistant import PDFAssistant
|
5 |
+
from modules.utils import load_css
|
6 |
+
|
7 |
+
def create_app():
|
8 |
+
# Initialize assistants
|
9 |
+
code_assistant = CodeAssistant()
|
10 |
+
docs_assistant = DocsAssistant()
|
11 |
+
pdf_assistant = PDFAssistant()
|
12 |
+
|
13 |
+
with gr.Blocks(css=load_css()) as demo:
|
14 |
+
gr.Markdown("# Enterprise RAG Assistant")
|
15 |
+
|
16 |
+
with gr.Tabs() as tabs:
|
17 |
+
# Code Assistant Tab
|
18 |
+
with gr.Tab("Code Assistant", id=1):
|
19 |
+
with gr.Row():
|
20 |
+
with gr.Column():
|
21 |
+
code_input = gr.Textbox(
|
22 |
+
label="Ask coding questions",
|
23 |
+
placeholder="Enter your coding question...",
|
24 |
+
lines=3
|
25 |
+
)
|
26 |
+
code_submit = gr.Button("Get Code Solution")
|
27 |
+
code_output = gr.Code(
|
28 |
+
label="Code Output",
|
29 |
+
language="python"
|
30 |
+
)
|
31 |
+
|
32 |
+
# Documentation Assistant Tab
|
33 |
+
with gr.Tab("Documentation Assistant", id=2):
|
34 |
+
with gr.Row():
|
35 |
+
with gr.Column():
|
36 |
+
docs_input = gr.Textbox(
|
37 |
+
label="Documentation Query",
|
38 |
+
placeholder="Ask about technical documentation...",
|
39 |
+
lines=3
|
40 |
+
)
|
41 |
+
docs_file = gr.File(
|
42 |
+
label="Upload Documentation",
|
43 |
+
file_types=[".pdf", ".txt", ".md"]
|
44 |
+
)
|
45 |
+
docs_submit = gr.Button("Search Documentation")
|
46 |
+
docs_output = gr.Markdown()
|
47 |
+
|
48 |
+
# PDF RAG Assistant Tab
|
49 |
+
with gr.Tab("PDF Assistant", id=3):
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column():
|
52 |
+
pdf_file = gr.File(
|
53 |
+
label="Upload PDF",
|
54 |
+
file_types=[".pdf"]
|
55 |
+
)
|
56 |
+
pdf_query = gr.Textbox(
|
57 |
+
label="Ask about the PDF",
|
58 |
+
placeholder="Enter your question about the PDF...",
|
59 |
+
lines=3
|
60 |
+
)
|
61 |
+
pdf_submit = gr.Button("Get Answer")
|
62 |
+
pdf_output = gr.Markdown()
|
63 |
+
|
64 |
+
# Event handlers
|
65 |
+
code_submit.click(
|
66 |
+
code_assistant.generate_response,
|
67 |
+
inputs=[code_input],
|
68 |
+
outputs=[code_output]
|
69 |
+
)
|
70 |
+
|
71 |
+
docs_submit.click(
|
72 |
+
docs_assistant.search_docs,
|
73 |
+
inputs=[docs_input, docs_file],
|
74 |
+
outputs=[docs_output]
|
75 |
+
)
|
76 |
+
|
77 |
+
pdf_submit.click(
|
78 |
+
pdf_assistant.answer_query,
|
79 |
+
inputs=[pdf_query, pdf_file],
|
80 |
+
outputs=[pdf_output]
|
81 |
+
)
|
82 |
+
|
83 |
+
return demo
|
84 |
+
|
85 |
+
if __name__ == "__main__":
|
86 |
+
app = create_app()
|
87 |
+
app.launch()
|
NEYIRE/assets/style.css
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Modern Enterprise Theme */
|
2 |
+
.gradio-container {
|
3 |
+
font-family: 'Inter', sans-serif;
|
4 |
+
max-width: 1200px !important;
|
5 |
+
margin: auto;
|
6 |
+
}
|
7 |
+
|
8 |
+
.tabs {
|
9 |
+
background: #f8f9fa;
|
10 |
+
border-radius: 10px;
|
11 |
+
padding: 20px;
|
12 |
+
}
|
13 |
+
|
14 |
+
.input-box {
|
15 |
+
border: 1px solid #e0e0e0;
|
16 |
+
border-radius: 8px;
|
17 |
+
padding: 12px;
|
18 |
+
}
|
19 |
+
|
20 |
+
.button {
|
21 |
+
background: #2d63c8;
|
22 |
+
color: white;
|
23 |
+
border-radius: 6px;
|
24 |
+
padding: 10px 20px;
|
25 |
+
transition: all 0.3s ease;
|
26 |
+
}
|
27 |
+
|
28 |
+
.button:hover {
|
29 |
+
background: #1e4a9d;
|
30 |
+
transform: translateY(-1px);
|
31 |
+
}
|
32 |
+
|
33 |
+
.output-box {
|
34 |
+
background: #ffffff;
|
35 |
+
border: 1px solid #e0e0e0;
|
36 |
+
border-radius: 8px;
|
37 |
+
padding: 16px;
|
38 |
+
margin-top: 12px;
|
39 |
+
}
|
NEYIRE/modules/code_assistant.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
|
4 |
+
class CodeAssistant:
|
5 |
+
def __init__(self):
|
6 |
+
self.model_name = "Qwen/Qwen2.5-Coder-32B-Instruct"
|
7 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
8 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
self.model_name,
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto"
|
12 |
+
)
|
13 |
+
|
14 |
+
def generate_response(self, query):
|
15 |
+
inputs = self.tokenizer(query, return_tensors="pt").to(self.model.device)
|
16 |
+
outputs = self.model.generate(
|
17 |
+
**inputs,
|
18 |
+
max_length=2048,
|
19 |
+
temperature=0.7,
|
20 |
+
top_p=0.95,
|
21 |
+
do_sample=True
|
22 |
+
)
|
23 |
+
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
NEYIRE/modules/docs_assistant.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
|
4 |
+
class DocsAssistant:
|
5 |
+
def __init__(self):
|
6 |
+
self.model_name = "Arc53/docsgpt-40b-falcon"
|
7 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
8 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
self.model_name,
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto"
|
12 |
+
)
|
13 |
+
|
14 |
+
def search_docs(self, query, doc_file):
|
15 |
+
# Process uploaded documentation
|
16 |
+
doc_content = self._process_doc_file(doc_file)
|
17 |
+
|
18 |
+
# Create prompt with context
|
19 |
+
prompt = f"Documentation: {doc_content}\nQuery: {query}"
|
20 |
+
|
21 |
+
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device)
|
22 |
+
outputs = self.model.generate(
|
23 |
+
**inputs,
|
24 |
+
max_length=1024,
|
25 |
+
temperature=0.3,
|
26 |
+
top_p=0.95
|
27 |
+
)
|
28 |
+
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
+
|
30 |
+
def _process_doc_file(self, file):
|
31 |
+
# Implementation for file processing
|
32 |
+
pass
|
NEYIRE/modules/pdf_assistant.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
import torch
|
3 |
+
from PyPDF2 import PdfReader
|
4 |
+
|
5 |
+
class PDFAssistant:
|
6 |
+
def __init__(self):
|
7 |
+
self.model_name = "meta-llama/Llama-3.3-70B-Instruct"
|
8 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
9 |
+
self.model = AutoModelForCausalLM.from_pretrained(
|
10 |
+
self.model_name,
|
11 |
+
torch_dtype=torch.bfloat16,
|
12 |
+
device_map="auto"
|
13 |
+
)
|
14 |
+
|
15 |
+
def answer_query(self, query, pdf_file):
|
16 |
+
# Extract text from PDF
|
17 |
+
pdf_text = self._extract_pdf_text(pdf_file)
|
18 |
+
|
19 |
+
# Create prompt with context
|
20 |
+
prompt = f"Context from PDF: {pdf_text}\nQuestion: {query}"
|
21 |
+
|
22 |
+
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device)
|
23 |
+
outputs = self.model.generate(
|
24 |
+
**inputs,
|
25 |
+
max_length=1024,
|
26 |
+
temperature=0.3,
|
27 |
+
top_p=0.95
|
28 |
+
)
|
29 |
+
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
30 |
+
|
31 |
+
def _extract_pdf_text(self, pdf_file):
|
32 |
+
reader = PdfReader(pdf_file)
|
33 |
+
text = ""
|
34 |
+
for page in reader.pages:
|
35 |
+
text += page.extract_text()
|
36 |
+
return text
|
NEYIRE/modules/utils.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
NEYIRE/requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio>=4.0.0
|
2 |
+
torch>=2.0.0
|
3 |
+
transformers>=4.30.0
|
4 |
+
pypdf2>=3.0.0
|
5 |
+
sentencepiece
|
6 |
+
accelerate
|