rasulbrur commited on
Commit
ec34f15
·
1 Parent(s): c29e353

Added updated intent

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -10
  2. main.py +16 -16
  3. voice/intent_classifier.py +22 -22
Dockerfile CHANGED
@@ -1,4 +1,3 @@
1
- # Use official Python image
2
  FROM python:3.10-slim
3
 
4
  # Install system dependencies
@@ -6,14 +5,12 @@ RUN apt-get update && \
6
  apt-get install -y wget ffmpeg unzip curl gcc && \
7
  rm -rf /var/lib/apt/lists/*
8
 
9
- # Set working directory
10
- WORKDIR /app
11
 
12
- # Set Hugging Face cache directory
13
- ENV HF_HOME=/app/cache
14
 
15
- # Create cache directory and set permissions
16
- RUN mkdir -p /app/cache /app/db && chmod -R 777 /app/cache /app/db
17
 
18
  # Copy your code into the container
19
  COPY . .
@@ -22,9 +19,6 @@ COPY . .
22
  RUN pip install --upgrade pip && pip install -r requirements.txt
23
  RUN pip install --no-cache-dir torch==2.2.0+cpu torchvision==0.17.0+cpu torchaudio==2.2.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
24
 
25
-
26
-
27
-
28
  # Install spaCy model
29
  RUN python -m spacy download en_core_web_lg
30
  # RUN python -m spacy download en_core_web_sm
 
 
1
  FROM python:3.10-slim
2
 
3
  # Install system dependencies
 
5
  apt-get install -y wget ffmpeg unzip curl gcc && \
6
  rm -rf /var/lib/apt/lists/*
7
 
8
+ WORKDIR /app
 
9
 
10
+ ENV HF_HOME=/app/cache
 
11
 
12
+ # Create cache directory and set permissions
13
+ RUN mkdir -p /app/cache /app/db && chmod -R 777 /app/cache /app/db
14
 
15
  # Copy your code into the container
16
  COPY . .
 
19
  RUN pip install --upgrade pip && pip install -r requirements.txt
20
  RUN pip install --no-cache-dir torch==2.2.0+cpu torchvision==0.17.0+cpu torchaudio==2.2.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
21
 
 
 
 
22
  # Install spaCy model
23
  RUN python -m spacy download en_core_web_lg
24
  # RUN python -m spacy download en_core_web_sm
main.py CHANGED
@@ -55,22 +55,22 @@ async def process_query(vosk_model_path, audio_data=None, query_text=None, use_r
55
 
56
  if intent:
57
  intent_to_module = {
58
- "get_net_income": ("modules.get_net_income", "GetNetIncome"),
59
- "get_revenue": ("modules.get_revenue", "GetRevenue"),
60
- "get_stock_price": ("modules.get_stock_price", "GetStockPrice"),
61
- "get_profit_margin": ("modules.get_profit_margin", "GetProfitMargin"),
62
- "get_company_profile": ("modules.get_company_profile", "GetCompanyProfile"),
63
- "get_market_cap": ("modules.get_market_cap", "GetMarketCap"),
64
- "get_historical_stock_price": ("modules.get_historical_stock_price", "GetHistoricalStockPrice"),
65
- "get_dividend_info": ("modules.get_dividend_info", "GetDividendInfo"),
66
- "get_balance_sheet": ("modules.get_balance_sheet", "GetBalanceSheet"),
67
- "get_cash_flow": ("modules.get_cash_flow", "GetCashFlow"),
68
- "get_financial_ratios": ("modules.get_financial_ratios", "GetFinancialRatios"),
69
- "get_earnings_per_share": ("modules.get_earnings_per_share", "GetEarningsPerShare"),
70
- "get_interest": ("modules.get_interest", "GetInterest"),
71
- "get_income_tax": ("modules.get_income_tax", "GetIncomeTax"),
72
- "get_cost_info": ("modules.get_cost_info", "GetCostInfo"),
73
- "get_research_info": ("modules.get_research_info", "GetResearchInfo")
74
 
75
  }
76
 
 
55
 
56
  if intent:
57
  intent_to_module = {
58
+ "net_income": ("modules.get_net_income", "GetNetIncome"),
59
+ "revenue": ("modules.get_revenue", "GetRevenue"),
60
+ "stock_price": ("modules.get_stock_price", "GetStockPrice"),
61
+ "profit_margin": ("modules.get_profit_margin", "GetProfitMargin"),
62
+ "company_info": ("modules.get_company_profile", "GetCompanyProfile"),
63
+ "market_capitalization": ("modules.get_market_cap", "GetMarketCap"),
64
+ "historical_stock_price": ("modules.get_historical_stock_price", "GetHistoricalStockPrice"),
65
+ "dividend_info": ("modules.get_dividend_info", "GetDividendInfo"),
66
+ "balance_sheet": ("modules.get_balance_sheet", "GetBalanceSheet"),
67
+ "cash_flow": ("modules.get_cash_flow", "GetCashFlow"),
68
+ "financial_ratios": ("modules.get_financial_ratios", "GetFinancialRatios"),
69
+ "earnings_per_share": ("modules.get_earnings_per_share", "GetEarningsPerShare"),
70
+ "interest_rate": ("modules.get_interest", "GetInterest"),
71
+ "income_tax": ("modules.get_income_tax", "GetIncomeTax"),
72
+ "cost_info": ("modules.get_cost_info", "GetCostInfo"),
73
+ "research_info": ("modules.get_research_info", "GetResearchInfo")
74
 
75
  }
76
 
voice/intent_classifier.py CHANGED
@@ -12,22 +12,22 @@ class IntentClassifier:
12
  self.nlp = spacy.load("en_core_web_lg") # "en_core_web_sm"
13
  self.classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli", from_pt=True)
14
  self.intents = [
15
- "get_net_income",
16
- "get_revenue",
17
- "get_stock_price",
18
- "get_profit_margin",
19
- "get_company_profile",
20
- "get_market_cap",
21
- "get_historical_stock_price",
22
- "get_dividend_info",
23
- "get_balance_sheet",
24
- "get_cash_flow",
25
- "get_financial_ratios",
26
- "get_earnings_per_share",
27
- "get_interest",
28
- "get_research_info",
29
- "get_cost_info",
30
- "get_income_tax"
31
  ]
32
 
33
  # Mapping of company names to ticker symbols (case-insensitive)
@@ -168,7 +168,7 @@ class IntentClassifier:
168
 
169
  # Step 3: Extract metric using keyword matching with synonyms
170
  text_lower = text.lower()
171
- if any(keyword in text_lower for keyword in ["net income", "net", "income"]):
172
  entities["metric"] = "netIncome"
173
  elif "revenue" in text_lower:
174
  entities["metric"] = "revenue"
@@ -176,19 +176,19 @@ class IntentClassifier:
176
  entities["metric"] = "netProfitMargin"
177
  elif any(keyword in text_lower for keyword in ["market cap", "market capitalization", "market"]):
178
  entities["metric"] = "mktCap"
179
- elif any(keyword in text_lower for keyword in ["payout ratio", "dividend payout"]):
180
  entities["metric"] = "payoutRatio"
181
  elif any(keyword in text_lower for keyword in ["current ratio", "liquidity ratio"]):
182
  entities["metric"] = "currentRatio"
183
- elif any(keyword in text_lower for keyword in ["eps", "earnings per share", "earnings"]):
184
  entities["metric"] = "eps"
185
  elif any(keyword in text_lower for keyword in ["stock", "stock price", "current price", "valuation", "price"]):
186
  entities["metric"] = "price"
187
- elif any(keyword in text_lower for keyword in ["company info", "about company", "who is"]):
188
  entities["metric"] = "ceo"
189
- elif any(keyword in text_lower for keyword in ["balance sheet", "sheet", "assets"]):
190
  entities["metric"] = "Assets&Liabilities"
191
- elif any(keyword in text_lower for keyword in ["historical", "earnings per share", "earnings"]):
192
  entities["metric"] = "historical"
193
  elif any(keyword in text_lower for keyword in ["cash", "flow", "cash flow"]):
194
  entities["metric"] = "cashFlowFromOperatingActivities"
 
12
  self.nlp = spacy.load("en_core_web_lg") # "en_core_web_sm"
13
  self.classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli", from_pt=True)
14
  self.intents = [
15
+ "net_income",
16
+ "revenue",
17
+ "stock_price",
18
+ "profit_margin",
19
+ "company_info",
20
+ "market_capitalization",
21
+ "historical_stock_price",
22
+ "dividend_info",
23
+ "balance_sheet",
24
+ "cash_flow",
25
+ "financial_ratios",
26
+ "earnings_per_share",
27
+ "interest_rate",
28
+ "research_info",
29
+ "cost_info",
30
+ "income_tax"
31
  ]
32
 
33
  # Mapping of company names to ticker symbols (case-insensitive)
 
168
 
169
  # Step 3: Extract metric using keyword matching with synonyms
170
  text_lower = text.lower()
171
+ if any(keyword in text_lower for keyword in ["income"]):
172
  entities["metric"] = "netIncome"
173
  elif "revenue" in text_lower:
174
  entities["metric"] = "revenue"
 
176
  entities["metric"] = "netProfitMargin"
177
  elif any(keyword in text_lower for keyword in ["market cap", "market capitalization", "market"]):
178
  entities["metric"] = "mktCap"
179
+ elif any(keyword in text_lower for keyword in ["payout ratio", "payout", "dividend" "dividend payout"]):
180
  entities["metric"] = "payoutRatio"
181
  elif any(keyword in text_lower for keyword in ["current ratio", "liquidity ratio"]):
182
  entities["metric"] = "currentRatio"
183
+ elif any(keyword in text_lower for keyword in ["eps", "earning", "earnings per share", "earnings"]):
184
  entities["metric"] = "eps"
185
  elif any(keyword in text_lower for keyword in ["stock", "stock price", "current price", "valuation", "price"]):
186
  entities["metric"] = "price"
187
+ elif any(keyword in text_lower for keyword in ["company info", "company", "about company", "who is"]):
188
  entities["metric"] = "ceo"
189
+ elif any(keyword in text_lower for keyword in ["balance sheet", "balance", "sheet", "assets"]):
190
  entities["metric"] = "Assets&Liabilities"
191
+ elif any(keyword in text_lower for keyword in ["historical"]):
192
  entities["metric"] = "historical"
193
  elif any(keyword in text_lower for keyword in ["cash", "flow", "cash flow"]):
194
  entities["metric"] = "cashFlowFromOperatingActivities"