Ankit93 commited on
Commit
de0fbc2
ยท
2 Parent(s): 916b2a26a0efde

Modification

Browse files
Files changed (3) hide show
  1. app.py +82 -57
  2. requirements.txt +0 -0
  3. src/llm/source_llm.py +1 -1
app.py CHANGED
@@ -1,76 +1,101 @@
1
- import re, uuid
2
- import json, logging
3
  import gradio as gr
4
- from typing import List, Dict
5
-
6
- from data.css import custom_css
7
  from src.controller.agent_cacher import AgentManager
 
8
  # Configure logging
9
  logging.basicConfig(level=logging.INFO, format="-->%(asctime)s [%(levelname)s] %(message)s")
10
 
11
-
12
-
 
 
 
13
 
14
  def create_gradio_interface():
15
- gr.HTML('<link href="https://fonts.googleapis.com/css2?family=Fira+Code&family=Roboto&display=swap" rel="stylesheet">')
16
- gr.HTML(custom_css)
17
  manager = AgentManager()
18
-
19
  with gr.Blocks(title="AI Learning Assistant") as demo:
20
- gr.Markdown("# ๐Ÿง  Learn with LlamaIndex Tools")
21
- logging.info("Starting Learning Application")
22
-
23
- with gr.Row():
24
- session_id = gr.Textbox(label="Session ID", value=str(uuid.uuid4()), visible=True)
25
- llm_selector = gr.Dropdown(
26
- label="LLM Type",
27
- choices=["Google", "OpenAI", "HuggingFace", "Mistral"],
28
- value="Google",
29
- interactive=True
30
- )
31
 
32
- with gr.Row():
33
- with gr.Column(scale=3):
34
- chatbot = gr.Chatbot(
35
- label="Learning Dialog",
36
- height=500,
37
- type="messages"
 
38
  )
39
- query_input = gr.Textbox(label="Your Learning Query", placeholder="Ask about ML/DL algorithms...")
40
- submit_btn = gr.Button("Submit")
41
-
42
- with gr.Column(scale=1):
43
- gr.Markdown("### Tools Preview")
44
- tool_output = gr.Textbox(label="Selected Tools", interactive=False)
45
- response_output = gr.Textbox(label="Full Response", interactive=False, lines=10)
46
-
47
- def process_query(session_id_val, query, chat_history, llm_val):
48
- print("Session:", session_id)
49
- print("Query:", query)
50
- #print("Chat History:", chat_history)
51
- print("Option selected:", llm_val)
52
- agent = manager.get_agent(session_id_val, llm_type=llm_val)
53
- chat_history, tools_used, response = agent.process_query(query)
54
- manager.save_agent(session_id_val, agent)
55
- return chat_history, tools_used, response, ""
56
-
57
- submit_btn.click(
58
- process_query,
59
- inputs=[session_id, query_input, chatbot, llm_selector], # โœ… 4 inputs
60
- outputs=[chatbot, tool_output, response_output, query_input]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  )
62
 
63
- def load_history(session_id_val, llm_val):
64
- agent = manager.get_agent(session_id_val, llm_val)
65
- return agent.chat_history
 
 
66
 
67
- session_id.change(
68
- load_history,
69
- inputs=[session_id, llm_selector], # โœ… Pass component objects, not .value
70
- outputs=chatbot
71
  )
72
 
73
  return demo
 
74
  if __name__ == "__main__":
75
  interface = create_gradio_interface()
76
- interface.launch()
 
 
 
1
  import gradio as gr
2
+ import uuid
3
+ import logging
 
4
  from src.controller.agent_cacher import AgentManager
5
+
6
  # Configure logging
7
  logging.basicConfig(level=logging.INFO, format="-->%(asctime)s [%(levelname)s] %(message)s")
8
 
9
+ # User credentials
10
+ VALID_USERS = {
11
+ "ankit": "mlpass123",
12
+ "demo": "test123"
13
+ }
14
 
15
  def create_gradio_interface():
 
 
16
  manager = AgentManager()
17
+
18
  with gr.Blocks(title="AI Learning Assistant") as demo:
19
+ auth_state = gr.State(False) # store login status
20
+
21
+ with gr.Column(visible=True) as login_section:
22
+ gr.Markdown("## ๐Ÿ” Login to Continue")
23
+ username = gr.Textbox(label="Username")
24
+ password = gr.Textbox(label="Password", type="password")
25
+ login_btn = gr.Button("Login")
26
+ login_error = gr.Markdown(visible=False)
27
+
28
+ with gr.Column(visible=False) as app_section:
29
+ gr.Markdown("# ๐Ÿง  Learn with LlamaIndex Tools")
30
 
31
+ with gr.Row():
32
+ session_id = gr.Textbox(label="Session ID", value=str(uuid.uuid4()), visible=True)
33
+ llm_selector = gr.Dropdown(
34
+ label="LLM Type",
35
+ choices=["Google", "OpenAI", "HuggingFace", "Mistral"],
36
+ value="Google",
37
+ interactive=True
38
  )
39
+
40
+ with gr.Row():
41
+ with gr.Column(scale=3):
42
+ chatbot = gr.Chatbot(label="Learning Dialog", height=500, type="messages")
43
+ query_input = gr.Textbox(label="Your Learning Query", placeholder="Ask about ML/DL algorithms...")
44
+ submit_btn = gr.Button("Submit")
45
+
46
+ with gr.Column(scale=1):
47
+ gr.Markdown("### Tools Preview")
48
+ tool_output = gr.Textbox(label="Selected Tools", interactive=False)
49
+ response_output = gr.Textbox(label="Full Response", interactive=False, lines=10)
50
+
51
+ def process_query(session_id_val, query, chat_history, llm_val):
52
+ agent = manager.get_agent(session_id_val, llm_type=llm_val)
53
+ chat_history, tools_used, response = agent.process_query(query)
54
+ manager.save_agent(session_id_val, agent)
55
+ return chat_history, tools_used, response, ""
56
+
57
+ submit_btn.click(
58
+ process_query,
59
+ inputs=[session_id, query_input, chatbot, llm_selector],
60
+ outputs=[chatbot, tool_output, response_output, query_input]
61
+ )
62
+
63
+ def load_history(session_id_val, llm_val):
64
+ agent = manager.get_agent(session_id_val, llm_val)
65
+ return agent.chat_history
66
+
67
+ session_id.change(
68
+ load_history,
69
+ inputs=[session_id, llm_selector],
70
+ outputs=chatbot
71
+ )
72
+
73
+ def check_login(username, password):
74
+ if username == "admin" and password == "123":
75
+ return "", True
76
+ else:
77
+ return "Invalid credentials", False
78
+
79
+ login_btn.click(
80
+ check_login,
81
+ inputs=[username, password],
82
+ outputs=[login_error, auth_state]
83
  )
84
 
85
+ def toggle_ui(is_logged_in):
86
+ return (
87
+ gr.update(visible=is_logged_in), # app_section
88
+ gr.update(visible=not is_logged_in) # login_section
89
+ )
90
 
91
+ auth_state.change(
92
+ toggle_ui,
93
+ inputs=auth_state,
94
+ outputs=[app_section, login_section]
95
  )
96
 
97
  return demo
98
+
99
  if __name__ == "__main__":
100
  interface = create_gradio_interface()
101
+ interface.launch()
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
 
src/llm/source_llm.py CHANGED
@@ -54,7 +54,7 @@ class LLMCall:
54
 
55
  def _get_google_llm(self):
56
  return GoogleGenAI(
57
- model="models/gemini-1.5-flash",
58
  )
59
 
60
  def _get_mistral(self):
 
54
 
55
  def _get_google_llm(self):
56
  return GoogleGenAI(
57
+ model="models/gemini-2.0-flash",
58
  )
59
 
60
  def _get_mistral(self):