add image extract
Browse files
app.py
CHANGED
|
@@ -10,7 +10,6 @@ from langchain_chroma import Chroma
|
|
| 10 |
from langchain.schema import HumanMessage, SystemMessage
|
| 11 |
from tiktoken import encoding_for_model
|
| 12 |
|
| 13 |
-
|
| 14 |
from fastapi import FastAPI, HTTPException
|
| 15 |
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
from pydantic import BaseModel
|
|
@@ -42,21 +41,6 @@ except Exception as e:
|
|
| 42 |
print("Can't init the modèle", e)
|
| 43 |
raise
|
| 44 |
|
| 45 |
-
# --- Initialisation de la base SQLite
|
| 46 |
-
conn = sqlite3.connect("conversations.db", check_same_thread=False)
|
| 47 |
-
cursor = conn.cursor()
|
| 48 |
-
cursor.execute('''
|
| 49 |
-
CREATE TABLE IF NOT EXISTS conversations (
|
| 50 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 51 |
-
domain TEXT,
|
| 52 |
-
model TEXT,
|
| 53 |
-
user_message TEXT,
|
| 54 |
-
bot_response TEXT,
|
| 55 |
-
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
| 56 |
-
)
|
| 57 |
-
''')
|
| 58 |
-
conn.commit()
|
| 59 |
-
|
| 60 |
def load_collection(domain):
|
| 61 |
persist_directory = os.path.join(VECTORSTORE_BASE_DIR, domain.lower())
|
| 62 |
vectordb = Chroma(
|
|
@@ -145,12 +129,6 @@ def respond(message, history, system_message, domain, model_name, max_tokens, te
|
|
| 145 |
history.append({"role": "user", "content": message})
|
| 146 |
history.append({"role": "assistant", "content": content})
|
| 147 |
|
| 148 |
-
# Optionnel : sauvegarde dans la base SQLite désactivée pour l'instant
|
| 149 |
-
# cursor.execute('''
|
| 150 |
-
# INSERT INTO conversations (domain, model, user_message, bot_response) VALUES (?, ?, ?, ?)
|
| 151 |
-
# ''', (domain, model_name, message, content))
|
| 152 |
-
# conn.commit()
|
| 153 |
-
|
| 154 |
return history
|
| 155 |
|
| 156 |
except Exception as e:
|
|
@@ -251,20 +229,27 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {background-color:
|
|
| 251 |
send_button.click(
|
| 252 |
fn=chat_submit,
|
| 253 |
inputs=[message_input, chatbot, domain, model_name, max_tokens, temperature, top_p],
|
| 254 |
-
outputs=[chatbot, message_input]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
)
|
| 256 |
|
| 257 |
-
|
|
|
|
| 258 |
if username == EXCELIS_USER and password == EXCELIS_MDP:
|
| 259 |
-
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 260 |
-
|
|
|
|
| 261 |
|
| 262 |
login_button.click(
|
| 263 |
-
fn=
|
| 264 |
inputs=[user_input, pass_input],
|
| 265 |
-
outputs=[login_block, chatbot_block,
|
| 266 |
)
|
| 267 |
-
|
|
|
|
| 268 |
if __name__ == "__main__":
|
| 269 |
-
|
| 270 |
-
app.launch()
|
|
|
|
| 10 |
from langchain.schema import HumanMessage, SystemMessage
|
| 11 |
from tiktoken import encoding_for_model
|
| 12 |
|
|
|
|
| 13 |
from fastapi import FastAPI, HTTPException
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
from pydantic import BaseModel
|
|
|
|
| 41 |
print("Can't init the modèle", e)
|
| 42 |
raise
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def load_collection(domain):
|
| 45 |
persist_directory = os.path.join(VECTORSTORE_BASE_DIR, domain.lower())
|
| 46 |
vectordb = Chroma(
|
|
|
|
| 129 |
history.append({"role": "user", "content": message})
|
| 130 |
history.append({"role": "assistant", "content": content})
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
return history
|
| 133 |
|
| 134 |
except Exception as e:
|
|
|
|
| 229 |
send_button.click(
|
| 230 |
fn=chat_submit,
|
| 231 |
inputs=[message_input, chatbot, domain, model_name, max_tokens, temperature, top_p],
|
| 232 |
+
outputs=[chatbot, message_input],
|
| 233 |
+
)
|
| 234 |
+
message_input.submit(
|
| 235 |
+
fn=chat_submit,
|
| 236 |
+
inputs=[message_input, chatbot, domain, model_name, max_tokens, temperature, top_p],
|
| 237 |
+
outputs=[chatbot, message_input],
|
| 238 |
)
|
| 239 |
|
| 240 |
+
# Login handler
|
| 241 |
+
def verify_login(username, password):
|
| 242 |
if username == EXCELIS_USER and password == EXCELIS_MDP:
|
| 243 |
+
return True, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 244 |
+
else:
|
| 245 |
+
return False, gr.update(visible=True, value="❌ Identifiant ou mot de passe incorrect"), gr.update(visible=False), gr.update(visible=False)
|
| 246 |
|
| 247 |
login_button.click(
|
| 248 |
+
fn=verify_login,
|
| 249 |
inputs=[user_input, pass_input],
|
| 250 |
+
outputs=[error_box, login_block, chatbot_block, id_extraction_block],
|
| 251 |
)
|
| 252 |
+
|
| 253 |
+
# --- Lancement serveur
|
| 254 |
if __name__ == "__main__":
|
| 255 |
+
app.launch()
|
|
|