Spaces:
Sleeping
Sleeping
Commit
·
60a5284
1
Parent(s):
0bad806
UPdate
Browse files- .gitignore +0 -1
- .gradio/certificate.pem +31 -0
- README.md +2 -2
- app.py +28 -23
- requirements.txt +9 -7
.gitignore
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
chroma_db/*
|
| 2 |
__pycache__/*
|
| 3 |
.venv
|
| 4 |
.env
|
|
|
|
|
|
|
| 1 |
__pycache__/*
|
| 2 |
.venv
|
| 3 |
.env
|
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+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NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5
|
| 24 |
+
ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur
|
| 25 |
+
TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 👁
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 1 |
---
|
| 2 |
+
title: GAIA Chatbot - level 3
|
| 3 |
emoji: 👁
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.13.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -1,7 +1,12 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import json
|
| 7 |
import gradio as gr
|
|
@@ -20,11 +25,12 @@ from llama_index.vector_stores.chroma import ChromaVectorStore
|
|
| 20 |
|
| 21 |
load_dotenv()
|
| 22 |
|
| 23 |
-
title = "
|
| 24 |
description = "Example of an assistant with Gradio, RAG from PDF documents and Mistral AI via its API"
|
| 25 |
placeholder = (
|
| 26 |
"Vous pouvez me posez une question sur ce contexte, appuyer sur Entrée pour valider"
|
| 27 |
)
|
|
|
|
| 28 |
llm_model = "open-mixtral-8x22b"
|
| 29 |
|
| 30 |
env_api_key = os.environ.get("MISTRAL_API_KEY")
|
|
@@ -82,36 +88,37 @@ def load_file(files):
|
|
| 82 |
for doc in documents:
|
| 83 |
index.insert(doc)
|
| 84 |
|
| 85 |
-
|
| 86 |
gr.Textbox(visible=False),
|
| 87 |
gr.Textbox(value=f"Document encoded ! You can ask questions", visible=True),
|
| 88 |
get_documents_in_db(),
|
| 89 |
)
|
| 90 |
|
| 91 |
|
| 92 |
-
def load_document(
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
with gr.Blocks() as demo:
|
| 98 |
gr.Markdown(
|
| 99 |
-
""" #
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
Mistral
|
| 104 |
|
| 105 |
*The files will stay in the database unless there is 48h of inactivty or you re-build the space.*
|
| 106 |
"""
|
| 107 |
)
|
| 108 |
|
| 109 |
-
gr.Markdown(""" ### 1 /
|
| 110 |
|
| 111 |
with gr.Row():
|
| 112 |
with gr.Column():
|
| 113 |
input_file = gr.File(
|
| 114 |
-
label="
|
| 115 |
file_types=[".pdf"],
|
| 116 |
file_count="multiple",
|
| 117 |
type="filepath",
|
|
@@ -123,33 +130,31 @@ with gr.Blocks() as demo:
|
|
| 123 |
|
| 124 |
input_file.upload(
|
| 125 |
fn=load_document,
|
| 126 |
-
inputs=
|
| 127 |
-
input_file,
|
| 128 |
-
],
|
| 129 |
outputs=[file_msg],
|
| 130 |
concurrency_limit=20,
|
| 131 |
)
|
| 132 |
|
| 133 |
help_msg = gr.Markdown(
|
| 134 |
-
value="
|
| 135 |
)
|
| 136 |
|
| 137 |
-
file_btn = gr.Button(value="
|
| 138 |
btn_msg = gr.Textbox(container=False, visible=False)
|
| 139 |
|
| 140 |
with gr.Row():
|
| 141 |
db_list = gr.Markdown(value=get_documents_in_db)
|
| 142 |
-
delete_btn = gr.Button(value="
|
| 143 |
|
| 144 |
file_btn.click(
|
| 145 |
load_file,
|
| 146 |
-
inputs=
|
| 147 |
outputs=[file_msg, btn_msg, db_list],
|
| 148 |
show_progress="full",
|
| 149 |
)
|
| 150 |
delete_btn.click(empty_db, outputs=[db_list], show_progress="minimal")
|
| 151 |
|
| 152 |
-
gr.Markdown(""" ### 2 /
|
| 153 |
|
| 154 |
chatbot = gr.Chatbot()
|
| 155 |
msg = gr.Textbox(placeholder=placeholder)
|
|
@@ -164,4 +169,4 @@ with gr.Blocks() as demo:
|
|
| 164 |
|
| 165 |
demo.title = title
|
| 166 |
|
| 167 |
-
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
+
# Try to import pysqlite3 for environments like Hugging Face Spaces
|
| 3 |
+
try:
|
| 4 |
+
__import__('pysqlite3')
|
| 5 |
+
import sys
|
| 6 |
+
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
|
| 7 |
+
except ImportError:
|
| 8 |
+
# pysqlite3 not available, use standard sqlite3 (works on most environments)
|
| 9 |
+
pass
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
import json
|
| 12 |
import gradio as gr
|
|
|
|
| 25 |
|
| 26 |
load_dotenv()
|
| 27 |
|
| 28 |
+
title = "Gaia Mistral 8x22b Chat RAG PDF Demo"
|
| 29 |
description = "Example of an assistant with Gradio, RAG from PDF documents and Mistral AI via its API"
|
| 30 |
placeholder = (
|
| 31 |
"Vous pouvez me posez une question sur ce contexte, appuyer sur Entrée pour valider"
|
| 32 |
)
|
| 33 |
+
placeholder_url = "Extract text from this url"
|
| 34 |
llm_model = "open-mixtral-8x22b"
|
| 35 |
|
| 36 |
env_api_key = os.environ.get("MISTRAL_API_KEY")
|
|
|
|
| 88 |
for doc in documents:
|
| 89 |
index.insert(doc)
|
| 90 |
|
| 91 |
+
return (
|
| 92 |
gr.Textbox(visible=False),
|
| 93 |
gr.Textbox(value=f"Document encoded ! You can ask questions", visible=True),
|
| 94 |
get_documents_in_db(),
|
| 95 |
)
|
| 96 |
|
| 97 |
|
| 98 |
+
def load_document(input_files):
|
| 99 |
+
for input_file in input_files:
|
| 100 |
+
file_name = input_file.name.split("/")[-1]
|
| 101 |
+
return gr.Textbox(value=f"Document loaded: {file_name}", visible=True)
|
| 102 |
|
| 103 |
|
| 104 |
with gr.Blocks() as demo:
|
| 105 |
gr.Markdown(
|
| 106 |
+
""" # Welcome to Gaia Level 3 Demo
|
| 107 |
|
| 108 |
+
Add a file before interacting with the Chat.
|
| 109 |
+
This demo allows you to interact with a pdf file and then ask questions to Mistral APIs.
|
| 110 |
+
Mistral will answer with the context extracted from your uploaded file.
|
| 111 |
|
| 112 |
*The files will stay in the database unless there is 48h of inactivty or you re-build the space.*
|
| 113 |
"""
|
| 114 |
)
|
| 115 |
|
| 116 |
+
gr.Markdown(""" ### 1 / Extract data from PDF """)
|
| 117 |
|
| 118 |
with gr.Row():
|
| 119 |
with gr.Column():
|
| 120 |
input_file = gr.File(
|
| 121 |
+
label="Load a pdf",
|
| 122 |
file_types=[".pdf"],
|
| 123 |
file_count="multiple",
|
| 124 |
type="filepath",
|
|
|
|
| 130 |
|
| 131 |
input_file.upload(
|
| 132 |
fn=load_document,
|
| 133 |
+
inputs=input_file,
|
|
|
|
|
|
|
| 134 |
outputs=[file_msg],
|
| 135 |
concurrency_limit=20,
|
| 136 |
)
|
| 137 |
|
| 138 |
help_msg = gr.Markdown(
|
| 139 |
+
value="Once the document is loaded, press the Encode button below to add it to the db."
|
| 140 |
)
|
| 141 |
|
| 142 |
+
file_btn = gr.Button(value="Encode file ✅", interactive=True)
|
| 143 |
btn_msg = gr.Textbox(container=False, visible=False)
|
| 144 |
|
| 145 |
with gr.Row():
|
| 146 |
db_list = gr.Markdown(value=get_documents_in_db)
|
| 147 |
+
delete_btn = gr.Button(value="Empty db 🗑️", interactive=True, scale=0)
|
| 148 |
|
| 149 |
file_btn.click(
|
| 150 |
load_file,
|
| 151 |
+
inputs=input_file,
|
| 152 |
outputs=[file_msg, btn_msg, db_list],
|
| 153 |
show_progress="full",
|
| 154 |
)
|
| 155 |
delete_btn.click(empty_db, outputs=[db_list], show_progress="minimal")
|
| 156 |
|
| 157 |
+
gr.Markdown(""" ### 2 / Ask a question about this context """)
|
| 158 |
|
| 159 |
chatbot = gr.Chatbot()
|
| 160 |
msg = gr.Textbox(placeholder=placeholder)
|
|
|
|
| 169 |
|
| 170 |
demo.title = title
|
| 171 |
|
| 172 |
+
demo.launch(share=True)
|
requirements.txt
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
-
pypdf
|
| 2 |
-
mistralai
|
| 3 |
-
gradio
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
llama-index-readers-file
|
| 9 |
llama-index-llms-mistralai
|
| 10 |
llama-index-embeddings-mistralai
|
|
|
|
| 1 |
+
pypdf==4.3.1
|
| 2 |
+
mistralai==1.0.1
|
| 3 |
+
gradio==4.44.0
|
| 4 |
+
python-dotenv==1.0.1
|
| 5 |
+
huggingface-hub==0.36.0
|
| 6 |
+
# sqlite3
|
| 7 |
+
# pysqlite3-binary
|
| 8 |
+
chromadb==0.5.5
|
| 9 |
+
llama-index==0.10.68
|
| 10 |
llama-index-readers-file
|
| 11 |
llama-index-llms-mistralai
|
| 12 |
llama-index-embeddings-mistralai
|