Jasur05 commited on
Commit
dbd5bdd
Β·
1 Parent(s): c2c163b
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -29,13 +29,14 @@ client = chromadb.Client()
29
  collection = client.get_or_create_collection(name="inha-well", embedding_function=None)
30
 
31
  # ─── 3. Ingestion & Embedding (run only once) ──────────────────────────────
 
32
  total_docs = collection.count() if hasattr(collection, 'count') else len(collection.get()['documents'])
33
 
34
  if total_docs == 0:
35
  content_chunks = []
36
  for i in range(1, 4):
37
  # Build the absolute path to each docs folder
38
- folder_path = f"docs/p0000{i}"
39
 
40
  # Add error handling for missing folders
41
  if not os.path.exists(folder_path):
@@ -77,7 +78,9 @@ def get_prompt_plain(context: str, question: str) -> str:
77
  return f"""
78
  <<START>>
79
  You are a responsible person for answering Inha University (South Korea) information. Using the context below, answer within 300 tokens.
80
- Provide concise, well-structured, answer-oriented responses. Do not repeat the prompt text in your output.
 
 
81
 
82
  Context:
83
  "{context}"
@@ -98,6 +101,7 @@ def generate_agent_answer(context: str, question: str) -> str:
98
  stop_sequences=["<<END>>", "<<START>>"]
99
  )
100
  )
 
101
  return response.text.strip()
102
 
103
  def rag_answer(question: str, collection) -> str:
@@ -114,7 +118,7 @@ def answer_question(question):
114
 
115
  try:
116
  answer = rag_answer(question, collection)
117
- return f"### Answer: \n{answer}" # Formatted answer with Markdown support
118
  except Exception as e:
119
  return f"Sorry, I encountered an error: {str(e)}"
120
 
@@ -127,11 +131,9 @@ demo = gr.Interface(
127
  placeholder="e.g. What clubs are available in the 4th semester?",
128
  lines=2
129
  ),
130
- outputs=gr.Textbox( # Using Textbox instead of Markdown
131
  label="πŸ“Œ Answer",
132
-
133
- show_copy_button=True,
134
- interactive=False # Disable interactivity for output field
135
  ),
136
  title="πŸ“š Inha University Info Assistant",
137
  description="Get answers to your questions about Inha University using AI-powered search.",
@@ -148,5 +150,5 @@ if __name__ == "__main__":
148
  demo.launch(
149
  share=True, # Creates a public link
150
  server_name="0.0.0.0", # Allows external access
151
-
152
- )
 
29
  collection = client.get_or_create_collection(name="inha-well", embedding_function=None)
30
 
31
  # ─── 3. Ingestion & Embedding (run only once) ──────────────────────────────
32
+ # Check if collection is empty to avoid re-ingesting on each run
33
  total_docs = collection.count() if hasattr(collection, 'count') else len(collection.get()['documents'])
34
 
35
  if total_docs == 0:
36
  content_chunks = []
37
  for i in range(1, 4):
38
  # Build the absolute path to each docs folder
39
+ folder_path = os.path.join(os.getcwd(), "docs", f"p0000{i}")
40
 
41
  # Add error handling for missing folders
42
  if not os.path.exists(folder_path):
 
78
  return f"""
79
  <<START>>
80
  You are a responsible person for answering Inha University (South Korea) information. Using the context below, answer within 300 tokens.
81
+ Provide concise, well-structured, answer-oriented responses using markdown formatting for better readability.
82
+ Use bullet points, bold text, and proper formatting to make the information clear and easy to read.
83
+ Do not repeat the prompt text in your output.
84
 
85
  Context:
86
  "{context}"
 
101
  stop_sequences=["<<END>>", "<<START>>"]
102
  )
103
  )
104
+ # Keep the markdown formatting for nice display
105
  return response.text.strip()
106
 
107
  def rag_answer(question: str, collection) -> str:
 
118
 
119
  try:
120
  answer = rag_answer(question, collection)
121
+ return answer
122
  except Exception as e:
123
  return f"Sorry, I encountered an error: {str(e)}"
124
 
 
131
  placeholder="e.g. What clubs are available in the 4th semester?",
132
  lines=2
133
  ),
134
+ outputs=gr.Markdown(
135
  label="πŸ“Œ Answer",
136
+ show_copy_button=True
 
 
137
  ),
138
  title="πŸ“š Inha University Info Assistant",
139
  description="Get answers to your questions about Inha University using AI-powered search.",
 
150
  demo.launch(
151
  share=True, # Creates a public link
152
  server_name="0.0.0.0", # Allows external access
153
+
154
+ )