Spaces:
Sleeping
Sleeping
prova chroma
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
|
@@ -198,4 +198,48 @@ if __name__ == "__main__":
|
|
| 198 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 199 |
|
| 200 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 201 |
-
demo.launch(debug=True, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import inspect
|
|
|
|
| 198 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
| 199 |
|
| 200 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
| 201 |
+
demo.launch(debug=True, share=False)
|
| 202 |
+
'''
|
| 203 |
+
import json
|
| 204 |
+
from langchain_chroma import Chroma
|
| 205 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 206 |
+
from langchain.tools.retriever import create_retriever_tool
|
| 207 |
+
|
| 208 |
+
import chromadb
|
| 209 |
+
chromadb.config.Settings.telemetry_enabled = False
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
if __name__=='__main__':
|
| 213 |
+
with open('metadata.jsonl', 'r') as jsonl_file:
|
| 214 |
+
json_list = list(jsonl_file)
|
| 215 |
+
|
| 216 |
+
json_QA = []
|
| 217 |
+
for json_str in json_list:
|
| 218 |
+
json_data = json.loads(json_str)
|
| 219 |
+
json_QA.append(json_data)
|
| 220 |
+
|
| 221 |
+
# Usa gli stessi embeddings
|
| 222 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
|
| 223 |
+
print(1)
|
| 224 |
+
|
| 225 |
+
# Inizializza Chroma
|
| 226 |
+
|
| 227 |
+
from langchain.schema import Document
|
| 228 |
+
from langchain_community.vectorstores import Chroma
|
| 229 |
+
|
| 230 |
+
# Prepara la lista di documenti
|
| 231 |
+
docs = []
|
| 232 |
+
print("orig:",len(json_QA))
|
| 233 |
+
for sample in json_QA:
|
| 234 |
+
print(len(docs))
|
| 235 |
+
content = f"Question : {sample['Question']}\n\nFinal answer : {sample['Final answer']}"
|
| 236 |
+
metadata = {"source": sample['task_id']}
|
| 237 |
+
doc = Document(page_content=content, metadata=metadata)
|
| 238 |
+
docs.append(doc)
|
| 239 |
+
|
| 240 |
+
# Inizializza il vector store Chroma
|
| 241 |
+
vector_store = Chroma.from_documents(
|
| 242 |
+
documents=docs,
|
| 243 |
+
embedding=embeddings,
|
| 244 |
+
persist_directory="./chroma_db"
|
| 245 |
+
)
|