Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,15 +45,17 @@ log_debug("Initializing RAG model...")
|
|
| 45 |
try:
|
| 46 |
#rag = RAGWithCitations(model_path_or_name=MODEL_CACHE_DIR)
|
| 47 |
rag = RAGWithCitations(
|
| 48 |
-
model_path_or_name="
|
| 49 |
-
max_tokens=2048, # Maximum tokens to generate (default: 2048)
|
| 50 |
-
temperature=0.0, # Sampling temperature (default: 0.0)
|
| 51 |
-
top_p=0.95, # Nucleus sampling parameter (default: 0.95)
|
| 52 |
-
repetition_penalty=1.0, # Penalty to reduce repetition (default: 1.0)
|
| 53 |
-
trust_remote_code=True, # Whether to trust remote code (default: True)
|
| 54 |
-
hf_token=os.getenv("HF_TOKEN")#, # Required for downloading predefined models
|
| 55 |
-
# models_dir=MODEL_CACHE_DIR # Custom directory for downloaded models
|
| 56 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# Fix the warnings by properly configuring generation parameters
|
| 59 |
# if hasattr(rag, "model"):
|
|
@@ -86,39 +88,39 @@ except Exception as e:
|
|
| 86 |
## Let's a do simple test from the doc --
|
| 87 |
|
| 88 |
# Define query and sources
|
| 89 |
-
query = "What is the capital of France?"
|
| 90 |
-
log_debug(f"π Test Query: {query}")
|
| 91 |
-
|
| 92 |
-
sources = [
|
| 93 |
-
{
|
| 94 |
-
"text": "Paris is the capital and most populous city of France.",
|
| 95 |
-
"metadata": {"source": "Geographic Encyclopedia", "reliability": "high"}
|
| 96 |
-
},
|
| 97 |
-
{
|
| 98 |
-
"text": "The Eiffel Tower is located in Paris, France.",
|
| 99 |
-
"metadata": {"source": "Travel Guide", "year": 2020}
|
| 100 |
-
}
|
| 101 |
-
]
|
| 102 |
-
log_debug("π Test Sources loaded successfully.")
|
| 103 |
|
| 104 |
# Generate a response
|
| 105 |
-
try:
|
| 106 |
-
log_debug("π§ Test rag model on simple example...")
|
| 107 |
-
rag1 = RAGWithCitations(
|
| 108 |
-
model_path_or_name="PleIAs/Pleias-RAG-350M"
|
| 109 |
-
)
|
| 110 |
-
response = rag1.generate(query,
|
| 111 |
-
sources #,
|
| 112 |
# do_sample=True, # Enable sampling
|
| 113 |
# top_p=0.95, # Set top_p for nucleus sampling
|
| 114 |
# pad_token_id=rag.tokenizer.eos_token_id, # Set pad_token_id to eos_token_id
|
| 115 |
# attention_mask=None # Ensure attention_mask is passed if needed
|
| 116 |
-
)
|
| 117 |
-
log_debug("β
Test Answer generated successfully.")
|
| 118 |
-
log_debug(response["processed"]["clean_answer"])
|
| 119 |
-
except Exception as e:
|
| 120 |
-
log_debug(f"β Test Answer generation failed: {str(e)}")
|
| 121 |
-
raise
|
| 122 |
|
| 123 |
|
| 124 |
|
|
@@ -180,14 +182,12 @@ def generate_answer(query, pdf_urls_str, debug_state=""):
|
|
| 180 |
gen_time = time.time() - start_time
|
| 181 |
debug_state = log_debug(f"β‘ Generation completed in {gen_time:.2f}s")
|
| 182 |
|
| 183 |
-
answer = response
|
| 184 |
-
backend = response.get('backend_used', 'unknown')
|
| 185 |
|
| 186 |
debug_state = log_debug(f"π‘ Answer preview: {answer[:200]}...")
|
| 187 |
-
debug_state = log_debug(f"π οΈ
|
| 188 |
|
| 189 |
-
|
| 190 |
-
return full_output, debug_state
|
| 191 |
|
| 192 |
except Exception as e:
|
| 193 |
error_msg = f"β Generation error: {str(e)}"
|
|
|
|
| 45 |
try:
|
| 46 |
#rag = RAGWithCitations(model_path_or_name=MODEL_CACHE_DIR)
|
| 47 |
rag = RAGWithCitations(
|
| 48 |
+
model_path_or_name="PleIAs/Pleias-RAG-350M"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
+
# model_path_or_name="1b_rag",
|
| 51 |
+
# max_tokens=2048, # Maximum tokens to generate (default: 2048)
|
| 52 |
+
# temperature=0.0, # Sampling temperature (default: 0.0)
|
| 53 |
+
# top_p=0.95, # Nucleus sampling parameter (default: 0.95)
|
| 54 |
+
# repetition_penalty=1.0, # Penalty to reduce repetition (default: 1.0)
|
| 55 |
+
# trust_remote_code=True, # Whether to trust remote code (default: True)
|
| 56 |
+
# hf_token=os.getenv("HF_TOKEN")#, # Required for downloading predefined models
|
| 57 |
+
# models_dir=MODEL_CACHE_DIR # Custom directory for downloaded models
|
| 58 |
+
# )
|
| 59 |
|
| 60 |
# Fix the warnings by properly configuring generation parameters
|
| 61 |
# if hasattr(rag, "model"):
|
|
|
|
| 88 |
## Let's a do simple test from the doc --
|
| 89 |
|
| 90 |
# Define query and sources
|
| 91 |
+
#query = "What is the capital of France?"
|
| 92 |
+
#log_debug(f"π Test Query: {query}")
|
| 93 |
+
|
| 94 |
+
#sources = [
|
| 95 |
+
# {
|
| 96 |
+
# "text": "Paris is the capital and most populous city of France.",
|
| 97 |
+
# "metadata": {"source": "Geographic Encyclopedia", "reliability": "high"}
|
| 98 |
+
# },
|
| 99 |
+
# {
|
| 100 |
+
# "text": "The Eiffel Tower is located in Paris, France.",
|
| 101 |
+
# "metadata": {"source": "Travel Guide", "year": 2020}
|
| 102 |
+
# }
|
| 103 |
+
#]
|
| 104 |
+
#log_debug("π Test Sources loaded successfully.")
|
| 105 |
|
| 106 |
# Generate a response
|
| 107 |
+
#try:
|
| 108 |
+
# log_debug("π§ Test rag model on simple example...")
|
| 109 |
+
# rag1 = RAGWithCitations(
|
| 110 |
+
# model_path_or_name="PleIAs/Pleias-RAG-350M"
|
| 111 |
+
# )
|
| 112 |
+
# response = rag1.generate(query,
|
| 113 |
+
# sources #,
|
| 114 |
# do_sample=True, # Enable sampling
|
| 115 |
# top_p=0.95, # Set top_p for nucleus sampling
|
| 116 |
# pad_token_id=rag.tokenizer.eos_token_id, # Set pad_token_id to eos_token_id
|
| 117 |
# attention_mask=None # Ensure attention_mask is passed if needed
|
| 118 |
+
# )
|
| 119 |
+
# log_debug("β
Test Answer generated successfully.")
|
| 120 |
+
# log_debug(response["processed"]["clean_answer"])
|
| 121 |
+
#except Exception as e:
|
| 122 |
+
# log_debug(f"β Test Answer generation failed: {str(e)}")
|
| 123 |
+
# raise
|
| 124 |
|
| 125 |
|
| 126 |
|
|
|
|
| 182 |
gen_time = time.time() - start_time
|
| 183 |
debug_state = log_debug(f"β‘ Generation completed in {gen_time:.2f}s")
|
| 184 |
|
| 185 |
+
answer = response["processed"]["clean_answer"]
|
|
|
|
| 186 |
|
| 187 |
debug_state = log_debug(f"π‘ Answer preview: {answer[:200]}...")
|
| 188 |
+
debug_state = log_debug(f"π οΈ Generated in {gen_time:.2f}s")
|
| 189 |
|
| 190 |
+
return answer, debug_state
|
|
|
|
| 191 |
|
| 192 |
except Exception as e:
|
| 193 |
error_msg = f"β Generation error: {str(e)}"
|