kanishka089 commited on
Commit
b9f5ac7
·
verified ·
1 Parent(s): 90cfba0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -14
app.py CHANGED
@@ -45,13 +45,15 @@ def ragChain(question: str) -> str:
45
  global chat_history
46
  retrievedDocuments = retriever.invoke(question)
47
  formattedContext = formatDocuments(retrievedDocuments)
48
- formattedPrompt = f"Question: {question}\n\nContext: {formattedContext}"
 
 
49
 
50
  messages = chat_history + [{"role": "user", "content": formattedPrompt}]
51
 
52
  response = client.chat_completion(
53
  messages=messages,
54
- max_tokens=500,
55
  stream=False
56
  )
57
  # Extract the generated response text using dataclass attributes
@@ -65,17 +67,37 @@ def ragChain(question: str) -> str:
65
 
66
  return generated_text or "No response generated"
67
 
68
-
69
  # Gradio interface
70
- interface = gr.Interface(
71
- fn=ragChain,
72
- inputs=gr.Textbox(label="Question"),
73
- outputs="text",
74
- title="Q & A on Sri Lankan Constitution",
75
- description="<div style='text-align: center;font-size: 18px;'>Brought to you by<a "
76
- "href='https://www.linkedin.com/in/kanishka-gunawardana-8955b937/' target='_blank'>"
77
- " Kanishka Yohan Gunawardana</a></div>"
78
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- # Launch the app
81
- interface.launch()
 
45
  global chat_history
46
  retrievedDocuments = retriever.invoke(question)
47
  formattedContext = formatDocuments(retrievedDocuments)
48
+ formattedPrompt = (f"Question: {question}\n\n"
49
+ f"Context: {formattedContext}\n\n"
50
+ f"Please provide a detailed and explanatory answer based solely on the provided context.")
51
 
52
  messages = chat_history + [{"role": "user", "content": formattedPrompt}]
53
 
54
  response = client.chat_completion(
55
  messages=messages,
56
+ max_tokens=800,
57
  stream=False
58
  )
59
  # Extract the generated response text using dataclass attributes
 
67
 
68
  return generated_text or "No response generated"
69
 
 
70
  # Gradio interface
71
+ with gr.Blocks() as demo:
72
+ with gr.Row():
73
+ with gr.Column():
74
+ textbox = gr.Textbox(label="Question")
75
+ with gr.Row():
76
+ buttonTerms = gr.Button("Terms")
77
+ button = gr.Button("Submit")
78
+
79
+ with gr.Column():
80
+ output = gr.Textbox(label="Output")
81
+
82
+
83
+ def on_button_click(question):
84
+ # Call the ragChain function with the question
85
+ answer = ragChain(question)
86
+ return answer
87
+
88
+ def on_term_button_click():
89
+ return ("The information provided by this application is generated using advanced technologies, including "
90
+ "natural language processing models, document retrieval systems, and embeddings-based search "
91
+ "algorithms. While these technologies are designed to offer accurate and relevant information, "
92
+ "they may not always be up-to-date or fully accurate.The owner of this application does not accept "
93
+ "any responsibility for potential inaccuracies, misleading information, or any consequences that may "
94
+ "arise from the use of the application. Users are encouraged to verify the information independently "
95
+ "and consult additional sources when making decisions based on the information provided by this app.")
96
+
97
+
98
+ # Bind the button to the function
99
+ button.click(on_button_click, inputs=textbox, outputs=output)
100
+ buttonTerms.click(on_term_button_click, outputs=output)
101
+
102
 
103
+ demo.launch()