ppsingh commited on
Commit
7f5ac0d
·
1 Parent(s): 77fab81

adding model params and QnA comp to UI

Browse files
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import streamlit as st
 
 
2
 
3
  col_title, col_about = st.columns([8, 2])
4
  with col_title:
@@ -6,15 +8,65 @@ with col_title:
6
  "<h1 style='text-align:center;'> Montreal AI Decisions (MVP)</h1>",
7
  unsafe_allow_html=True
8
  )
9
- with col_about:
10
- with st.expander("ℹ️ About this prototype"):
11
- st.markdown(
12
- """
13
- - **Data**: Public decisions under the Montreal Protocol.
14
- - **Search**: Semantic (with a 0.3 cosine threshold).
15
- - **RAG**: Answers generated with top-5 semantic search results as context.
16
- ⚠️ For testing only; do not input sensitive info.
17
- AI answers may be incorrect or misleading.
18
- """,
19
- unsafe_allow_html=True
20
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from utils.retriever import retrieve_paragraphs
3
+ from utils.generator import generate
4
 
5
  col_title, col_about = st.columns([8, 2])
6
  with col_title:
 
8
  "<h1 style='text-align:center;'> Montreal AI Decisions (MVP)</h1>",
9
  unsafe_allow_html=True
10
  )
11
+
12
+ async def chat_response(query):
13
+ """Generate chat response based on method and inputs"""
14
+
15
+ try:
16
+ retrieved_paragraphs = retrieve_paragraphs(query)
17
+ context_retrieved = ast.literal_eval(retrieved_paragraphs)
18
+
19
+ # Build list of only content, no metadata
20
+ context_retrieved_formatted = "||".join(doc['answer'] for doc in context_retrieved)
21
+ context_retrieved_lst = [doc['answer'] for doc in context_retrieved]
22
+
23
+ # # Prepare HTML for displaying source documents
24
+ # docs_html = []
25
+ # for i, d in enumerate(context_retrieved, 1):
26
+ # docs_html.append(make_html_source(d, i))
27
+ # docs_html = "".join(docs_html)
28
+
29
+ # Generate response
30
+ response = await generate(query=query, context=context_retrieved_lst)
31
+
32
+ # Add disclaimer to the response
33
+ response_with_disclaimer = BEGINNING_TEXT + response
34
+ # Log the interaction
35
+ # try:
36
+ # chat_logger.log(
37
+ # query=query,
38
+ # answer=response,
39
+ # retrieved_content=context_retrieved_lst,
40
+ # request=request
41
+ # )
42
+ # except Exception as e:
43
+ # print(f"Logging error: {str(e)}")
44
+
45
+
46
+ # Stream response character by character
47
+ displayed_response = ""
48
+ for i, char in enumerate(response_with_disclaimer):
49
+ displayed_response += char
50
+
51
+ yield displayed_response
52
+ # Only add delay every few characters to avoid being too slow
53
+ if i % 3 == 0:
54
+ await asyncio.sleep(0.02)
55
+
56
+ except Exception as e:
57
+ error_message = f"Error processing request: {str(e)}"
58
+ yield error_message
59
+
60
+ # 10.1. Question input
61
+ query = st.text_input(
62
+ label="Enter your question:",
63
+ key="query",
64
+ on_change=reset_page
65
+ )
66
+
67
+ # Only run search & display if user has entered something
68
+ if not query.strip():
69
+ st.info("Please enter a question to see results.")
70
+ st.stop()
71
+ else:
72
+ st.write_stream(chat_response(query))
model_params.cfg ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [generator]
2
+ PROVIDER = huggingface
3
+ MODEL = meta-llama/Meta-Llama-3-8B-Instruct
4
+ MAX_TOKENS = 768
5
+ TEMPERATURE = 0.2
6
+ INFERENCE_PROVIDER = novita
7
+ ORGANIZATION = GIZ
utils/__pycache__/generator.cpython-311.pyc ADDED
Binary file (8.76 kB). View file
 
utils/__pycache__/retriever.cpython-311.pyc ADDED
Binary file (1.2 kB). View file