Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,9 @@ import numpy as np
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import gradio as gr
|
| 7 |
import logging
|
|
|
|
| 8 |
|
| 9 |
-
# Load environment variables
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
# Define OpenAI-based model
|
|
@@ -72,6 +73,15 @@ class LocalEmbeddingStore:
|
|
| 72 |
print(f"Search results: {results}") # Debugging: Print results to check for any issues
|
| 73 |
return results['documents'], results['distances']
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Modify RAGSystem to integrate ChromaDB search
|
| 76 |
class RAGSystem:
|
| 77 |
def __init__(self, openai_client, embedding_store):
|
|
@@ -133,4 +143,21 @@ with gr.Blocks() as demo:
|
|
| 133 |
submit_button.click(chat_ui, inputs=[user_input, api_key_input, chat_history], outputs=chat_history)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
demo.launch()
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import gradio as gr
|
| 7 |
import logging
|
| 8 |
+
from huggingface_hub import HfApi, HfFolder
|
| 9 |
|
| 10 |
+
# Load environment variables
|
| 11 |
load_dotenv()
|
| 12 |
|
| 13 |
# Define OpenAI-based model
|
|
|
|
| 73 |
print(f"Search results: {results}") # Debugging: Print results to check for any issues
|
| 74 |
return results['documents'], results['distances']
|
| 75 |
|
| 76 |
+
def add_embedding(self, document_id, embedding, metadata=None):
|
| 77 |
+
"""Add a new embedding to the collection."""
|
| 78 |
+
self.collection.add(
|
| 79 |
+
ids=[document_id],
|
| 80 |
+
embeddings=[embedding.tolist()],
|
| 81 |
+
metadatas=[metadata] if metadata else None
|
| 82 |
+
)
|
| 83 |
+
print(f"Added embedding for document ID: {document_id}")
|
| 84 |
+
|
| 85 |
# Modify RAGSystem to integrate ChromaDB search
|
| 86 |
class RAGSystem:
|
| 87 |
def __init__(self, openai_client, embedding_store):
|
|
|
|
| 143 |
submit_button.click(chat_ui, inputs=[user_input, api_key_input, chat_history], outputs=chat_history)
|
| 144 |
|
| 145 |
if __name__ == "__main__":
|
| 146 |
+
# Load Hugging Face token from environment variables
|
| 147 |
+
hf_token = os.getenv("HUGGINGFACE_TOKEN")
|
| 148 |
+
if not hf_token:
|
| 149 |
+
raise ValueError("Hugging Face token not found in environment variables.")
|
| 150 |
+
|
| 151 |
+
# Set up the Hugging Face token for any necessary API calls
|
| 152 |
+
os.environ["HUGGINGFACE_TOKEN"] = hf_token
|
| 153 |
+
|
| 154 |
+
# Verify token permissions (optional)
|
| 155 |
+
try:
|
| 156 |
+
api = HfApi()
|
| 157 |
+
api.whoami(token=hf_token)
|
| 158 |
+
print("Hugging Face token is valid and has the necessary permissions.")
|
| 159 |
+
except Exception as e:
|
| 160 |
+
print(f"Error verifying Hugging Face token: {e}")
|
| 161 |
+
raise ValueError("Invalid Hugging Face token or insufficient permissions.")
|
| 162 |
+
|
| 163 |
demo.launch()
|