invincible-jha commited on
Commit
190c369
·
verified ·
1 Parent(s): c100279

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -55
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import sys
3
  import logging
@@ -11,7 +12,7 @@ from crewai import Agent
11
  from huggingface_hub import InferenceClient
12
  import json
13
  import warnings
14
- from typing import Literal
15
 
16
  # Suppress all deprecation warnings
17
  warnings.filterwarnings("ignore", category=DeprecationWarning)
@@ -68,7 +69,6 @@ class CommunicationExpertAgent(Agent):
68
  return rephrased_query
69
 
70
  def analyze_emotional_context(self, query):
71
- # This is a placeholder. In a real scenario, you'd use sentiment analysis or a more sophisticated method.
72
  if any(word in query.lower() for word in ['frustrated', 'angry', 'upset']):
73
  return "The user seems frustrated or upset."
74
  elif any(word in query.lower() for word in ['confused', 'unclear', 'don\'t understand']):
@@ -112,56 +112,6 @@ class PostprocessingAgent(Agent):
112
  response += "\n\nThank you for choosing Zerodha. Is there anything else I can assist you with today?"
113
  return response
114
 
115
- # Instantiate agents
116
- communication_expert = CommunicationExpertAgent()
117
- response_expert = ResponseExpertAgent()
118
- postprocessing_agent = PostprocessingAgent()
119
-
120
- async def handle_query(query):
121
- try:
122
- if not query.strip():
123
- return "I'm sorry, but I didn't receive any query. Could you please ask a question about Zerodha's services?"
124
-
125
- rephrased_query = await communication_expert.run(query)
126
- response = await response_expert.run(rephrased_query)
127
- final_response = postprocessing_agent.run(response)
128
- return final_response
129
- except Exception as e:
130
- logger.error(f"Error in handle_query: {str(e)}")
131
- return "I apologize, but an error occurred while processing your request. Please try again or contact Zerodha support if the issue persists."
132
-
133
- # Gradio interface setup
134
- def setup_interface():
135
- with gr.Blocks() as app:
136
- gr.Markdown("# Zerodha Support Chatbot")
137
- gr.Markdown("Ask questions about Zerodha's services, trading, account management, and more.")
138
-
139
- with gr.Row():
140
- query_input = gr.Textbox(label="Enter your query", placeholder="Type your question here...")
141
- submit_button = gr.Button("Submit")
142
-
143
- response_output = gr.Textbox(label="Response", lines=10)
144
-
145
- submit_button.click(
146
- fn=lambda x: asyncio.run(handle_query(x)),
147
- inputs=[query_input],
148
- outputs=[response_output]
149
- )
150
-
151
- gr.Examples(
152
- examples=[
153
- "How do I open a Zerodha account?",
154
- "What are the brokerage charges for intraday trading?",
155
- "Can you explain how to use the Kite platform?",
156
- "I'm having trouble logging into my account. What should I do?",
157
- "What are the margin requirements for F&O trading?"
158
- ],
159
- inputs=[query_input]
160
- )
161
-
162
- return app
163
-
164
- app = setup_interface()
165
-
166
- if __name__ == "__main__":
167
- app.launch()
 
1
+ ```python
2
  import os
3
  import sys
4
  import logging
 
12
  from huggingface_hub import InferenceClient
13
  import json
14
  import warnings
15
+ from typing import Literal, Tuple
16
 
17
  # Suppress all deprecation warnings
18
  warnings.filterwarnings("ignore", category=DeprecationWarning)
 
69
  return rephrased_query
70
 
71
  def analyze_emotional_context(self, query):
 
72
  if any(word in query.lower() for word in ['frustrated', 'angry', 'upset']):
73
  return "The user seems frustrated or upset."
74
  elif any(word in query.lower() for word in ['confused', 'unclear', 'don\'t understand']):
 
112
  response += "\n\nThank you for choosing Zerodha. Is there anything else I can assist you with today?"
113
  return response
114
 
115
+ class RelationshipManagerAgent(Agent):
116
+ role: Literal["Relationship Manager"] = "Relationship Manager"
117
+ goal: Literal["To elevate