Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import nltk
|
|
| 9 |
# Download the required NLTK data
|
| 10 |
nltk.download('punkt')
|
| 11 |
nltk.download('punkt_tab')
|
|
|
|
| 12 |
# Paths to your files
|
| 13 |
faiss_path = "manual_chunked_faiss_index_500.bin"
|
| 14 |
manual_path = "ubuntu_manual.txt"
|
|
@@ -48,7 +49,11 @@ except Exception as e:
|
|
| 48 |
raise RuntimeError(f"Failed to load FAISS index: {e}")
|
| 49 |
|
| 50 |
# Load the tokenizer and model for embeddings
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# OpenAI API key
|
| 54 |
openai.api_key = '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'
|
|
@@ -115,6 +120,8 @@ def rag_response(query, k=5, max_tokens=150):
|
|
| 115 |
except Exception as e:
|
| 116 |
return f"An error occurred: {e}", [], []
|
| 117 |
|
|
|
|
|
|
|
| 118 |
# Gradio Interface
|
| 119 |
def format_output(response, distances, indices):
|
| 120 |
formatted_response = f"Response: {response}\n\nDistances: {distances}\n\nIndices: {indices}"
|
|
|
|
| 9 |
# Download the required NLTK data
|
| 10 |
nltk.download('punkt')
|
| 11 |
nltk.download('punkt_tab')
|
| 12 |
+
|
| 13 |
# Paths to your files
|
| 14 |
faiss_path = "manual_chunked_faiss_index_500.bin"
|
| 15 |
manual_path = "ubuntu_manual.txt"
|
|
|
|
| 49 |
raise RuntimeError(f"Failed to load FAISS index: {e}")
|
| 50 |
|
| 51 |
# Load the tokenizer and model for embeddings
|
| 52 |
+
from transformers import AutoTokenizer, AutoModel
|
| 53 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/MiniLM-L12-H384-uncased")
|
| 54 |
+
model = AutoModel.from_pretrained("microsoft/MiniLM-L12-H384-uncased")
|
| 55 |
+
|
| 56 |
+
embedding_model = SentenceTransformer('microsoft/MiniLM-L12-H384-uncased')
|
| 57 |
|
| 58 |
# OpenAI API key
|
| 59 |
openai.api_key = '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'
|
|
|
|
| 120 |
except Exception as e:
|
| 121 |
return f"An error occurred: {e}", [], []
|
| 122 |
|
| 123 |
+
# Gradio Interface
|
| 124 |
+
|
| 125 |
# Gradio Interface
|
| 126 |
def format_output(response, distances, indices):
|
| 127 |
formatted_response = f"Response: {response}\n\nDistances: {distances}\n\nIndices: {indices}"
|