helmfridsson commited on
Commit
a673fe6
·
verified ·
1 Parent(s): 04b0333

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -1,4 +1,8 @@
1
  import json
 
 
 
 
2
  import gradio as gr
3
 
4
  from rag.search import search
@@ -7,12 +11,6 @@ from llm.reasoning import generate_reasoning
7
  from llm.reasoning import generate_reasoning_from_prompt
8
  from rag.ingest import ingest_pdfs_and_web, save_chunks
9
 
10
- import base64
11
-
12
- import os
13
-
14
- import time
15
-
16
  print("🔄 Startar RAG-ingest")
17
  DATA_DIR = "rag/data"
18
  start_time = time.perf_counter()
@@ -38,6 +36,16 @@ with open("content.json", encoding="utf-8") as f:
38
 
39
  DOC_INDEX = {d["id"]: d for d in DOCUMENTS}
40
 
 
 
 
 
 
 
 
 
 
 
41
  # =====================================================
42
  # FUNKTIONER
43
  # =====================================================
@@ -111,15 +119,13 @@ def clear_all():
111
 
112
  def format_source_link(chunk: dict) -> str:
113
  source = chunk.get("source", "Okänd källa")
114
- source_type = chunk.get("source_type")
115
 
116
- if source_type == "pdf":
117
- return f"[{source}](/file=rag/files/{source})"
118
 
119
- if source_type == "web":
120
  return f"[{source}]({source})"
121
 
122
- # Fallback – visa åtminstone namnet
123
  return source
124
 
125
 
 
1
  import json
2
+ import base64
3
+ import os
4
+ import shutil
5
+ import time
6
  import gradio as gr
7
 
8
  from rag.search import search
 
11
  from llm.reasoning import generate_reasoning_from_prompt
12
  from rag.ingest import ingest_pdfs_and_web, save_chunks
13
 
 
 
 
 
 
 
14
  print("🔄 Startar RAG-ingest")
15
  DATA_DIR = "rag/data"
16
  start_time = time.perf_counter()
 
36
 
37
  DOC_INDEX = {d["id"]: d for d in DOCUMENTS}
38
 
39
+ PUBLIC_DIR = "/tmp/gradio/public_pdfs"
40
+ os.makedirs(PUBLIC_DIR, exist_ok=True)
41
+
42
+ for file in os.listdir("rag/files"):
43
+ if file.lower().endswith(".pdf"):
44
+ shutil.copy(
45
+ os.path.join("rag/files", file),
46
+ os.path.join(PUBLIC_DIR, file)
47
+ )
48
+
49
  # =====================================================
50
  # FUNKTIONER
51
  # =====================================================
 
119
 
120
  def format_source_link(chunk: dict) -> str:
121
  source = chunk.get("source", "Okänd källa")
 
122
 
123
+ if chunk.get("source_type") == "pdf":
124
+ return f"[{source}](/file={PUBLIC_DIR}/{source})"
125
 
126
+ if chunk.get("source_type") == "web":
127
  return f"[{source}]({source})"
128
 
 
129
  return source
130
 
131