Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ import torch
|
|
| 10 |
|
| 11 |
# ========== Configuration ==========
|
| 12 |
EMBEDDING_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2" # Embedding model
|
| 13 |
-
LLM_MODEL_NAME = "
|
| 14 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 15 |
|
| 16 |
# ========== Text Splitting ==========
|
|
@@ -36,7 +36,7 @@ def get_vector_store(chunks):
|
|
| 36 |
raise RuntimeError(f"Error processing embeddings: {e}")
|
| 37 |
|
| 38 |
# ========== Response Generation ==========
|
| 39 |
-
class
|
| 40 |
def __init__(self):
|
| 41 |
try:
|
| 42 |
self.tokenizer = AutoTokenizer.from_pretrained(LLM_MODEL_NAME)
|
|
@@ -46,7 +46,7 @@ class MultilingualChat:
|
|
| 46 |
low_cpu_mem_usage=True
|
| 47 |
).to(DEVICE)
|
| 48 |
except Exception as e:
|
| 49 |
-
raise RuntimeError(f"Error loading model: {e}")
|
| 50 |
|
| 51 |
def generate(self, context, question):
|
| 52 |
try:
|
|
@@ -68,7 +68,7 @@ class MultilingualChat:
|
|
| 68 |
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 69 |
except Exception as e:
|
| 70 |
raise RuntimeError(f"Error generating response: {e}")
|
| 71 |
-
|
| 72 |
# ========== Streamlit App ==========
|
| 73 |
def clear_chat_history():
|
| 74 |
st.session_state.messages = [{"role": "assistant", "content": "در خدمتیم"}]
|
|
@@ -127,7 +127,7 @@ def main():
|
|
| 127 |
context = "\n".join([d.page_content for d in docs])
|
| 128 |
|
| 129 |
# Generate response
|
| 130 |
-
chat_model = DeepSeekChat()
|
| 131 |
response = chat_model.generate(context, prompt)
|
| 132 |
|
| 133 |
# Display response
|
|
|
|
| 10 |
|
| 11 |
# ========== Configuration ==========
|
| 12 |
EMBEDDING_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2" # Embedding model
|
| 13 |
+
LLM_MODEL_NAME = "deepseek-ai/deepseek-llm-67b-chat" # Replace with a valid model name
|
| 14 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 15 |
|
| 16 |
# ========== Text Splitting ==========
|
|
|
|
| 36 |
raise RuntimeError(f"Error processing embeddings: {e}")
|
| 37 |
|
| 38 |
# ========== Response Generation ==========
|
| 39 |
+
class DeepSeekChat: # Define the class here
|
| 40 |
def __init__(self):
|
| 41 |
try:
|
| 42 |
self.tokenizer = AutoTokenizer.from_pretrained(LLM_MODEL_NAME)
|
|
|
|
| 46 |
low_cpu_mem_usage=True
|
| 47 |
).to(DEVICE)
|
| 48 |
except Exception as e:
|
| 49 |
+
raise RuntimeError(f"Error loading DeepSeek model: {e}")
|
| 50 |
|
| 51 |
def generate(self, context, question):
|
| 52 |
try:
|
|
|
|
| 68 |
return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 69 |
except Exception as e:
|
| 70 |
raise RuntimeError(f"Error generating response: {e}")
|
| 71 |
+
|
| 72 |
# ========== Streamlit App ==========
|
| 73 |
def clear_chat_history():
|
| 74 |
st.session_state.messages = [{"role": "assistant", "content": "در خدمتیم"}]
|
|
|
|
| 127 |
context = "\n".join([d.page_content for d in docs])
|
| 128 |
|
| 129 |
# Generate response
|
| 130 |
+
chat_model = DeepSeekChat() # Use the defined class
|
| 131 |
response = chat_model.generate(context, prompt)
|
| 132 |
|
| 133 |
# Display response
|