Neom99 commited on
Commit
ad85c1e
·
verified ·
1 Parent(s): 97e31f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -8,8 +8,11 @@ import re # For regex to clean markdown
8
 
9
  # --- RAG Libraries ---
10
  from langchain.text_splitter import RecursiveCharacterTextSplitter
 
 
11
  from langchain_google_genai import GoogleGenerativeAIEmbeddings
12
- from langchain_google_genai.chat_models import ChatGoogleGenAI # Corrected import path
 
13
  from langchain.chains import RetrievalQA
14
  from langchain.prompts import PromptTemplate
15
  from langchain.schema import Document
@@ -17,7 +20,7 @@ from langchain_community.vectorstores import FAISS # Explicitly import FAISS
17
 
18
  # --- File Generation Libraries ---
19
  from fpdf import FPDF # For PDF
20
- from docx import Document # Changed: Import Document directly
21
  from docx.shared import Inches # For document formatting in Word
22
  from docx.enum.text import WD_ALIGN_PARAGRAPH # For text alignment in Word
23
 
@@ -42,10 +45,10 @@ else:
42
  try:
43
  llm_model_id = "gemini-1.5-flash" # The intended model ID
44
 
45
- # Explicitly pass the API key to ChatGoogleGenerativeAI
46
- llm = ChatGoogleGenAI(model=llm_model_id, temperature=0.7, google_api_key=google_api_key)
47
 
48
- # Explicitly pass the API key to GoogleGenerativeAIEmbeddings
49
  embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=google_api_key)
50
 
51
  rag_initialized = True
@@ -383,7 +386,7 @@ def perform_ticket_analysis(file, query):
383
  'Category': 'General Analysis',
384
  'Sub-Category': 'Uncategorized',
385
  'Count': 1,
386
- 'Issue Description (Summary)': raw_rag_output.strip()[:500] + '...' if len(raw_rag_output.strip()) > 500 else raw_rag_output.strip(),
387
  'Root Cause (Inferred)': 'N/A',
388
  'Potential Resolution Steps': 'N/A',
389
  'Future Prediction': 'N/A',
@@ -431,7 +434,7 @@ def perform_ticket_analysis(file, query):
431
  <p style="font-size: 0.9em; color: #555;">
432
  *Note: AI-generated insights, especially 'Root Cause', 'Future Prediction', and 'Proactive Measures', are inferred based on the provided ticket descriptions. These are educated guesses by the AI and should be used for **guidance only**. For critical business decisions, human expert validation is highly recommended.*
433
  </p>
434
- <p style="font-size: 0.8em; color: #777;">
435
  Report generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
436
  </p>
437
  </div>
 
8
 
9
  # --- RAG Libraries ---
10
  from langchain.text_splitter import RecursiveCharacterTextSplitter
11
+ # CHANGED: Updated import paths for ChatGoogleGenerativeAI and GoogleGenerativeAIEmbeddings
12
+ # GoogleGenerativeAIEmbeddings is usually directly under langchain_google_genai
13
  from langchain_google_genai import GoogleGenerativeAIEmbeddings
14
+ # ChatGoogleGenerativeAI has moved to generative_models submodule
15
+ from langchain_google_genai.generative_models import ChatGoogleGenerativeAI # CORRECTED IMPORT PATH
16
  from langchain.chains import RetrievalQA
17
  from langchain.prompts import PromptTemplate
18
  from langchain.schema import Document
 
20
 
21
  # --- File Generation Libraries ---
22
  from fpdf import FPDF # For PDF
23
+ from docx import Document # Import Document directly for python-docx
24
  from docx.shared import Inches # For document formatting in Word
25
  from docx.enum.text import WD_ALIGN_PARAGRAPH # For text alignment in Word
26
 
 
45
  try:
46
  llm_model_id = "gemini-1.5-flash" # The intended model ID
47
 
48
+ # CHANGED: Use the correct class name ChatGoogleGenerativeAI
49
+ llm = ChatGoogleGenerativeAI(model=llm_model_id, temperature=0.7, google_api_key=google_api_key)
50
 
51
+ # GoogleGenerativeAIEmbeddings usually remains directly under langchain_google_genai
52
  embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=google_api_key)
53
 
54
  rag_initialized = True
 
386
  'Category': 'General Analysis',
387
  'Sub-Category': 'Uncategorized',
388
  'Count': 1,
389
+ 'Issue Description (Summary)': raw_rag_output.strip(), # No truncation here either for fallback
390
  'Root Cause (Inferred)': 'N/A',
391
  'Potential Resolution Steps': 'N/A',
392
  'Future Prediction': 'N/A',
 
434
  <p style="font-size: 0.9em; color: #555;">
435
  *Note: AI-generated insights, especially 'Root Cause', 'Future Prediction', and 'Proactive Measures', are inferred based on the provided ticket descriptions. These are educated guesses by the AI and should be used for **guidance only**. For critical business decisions, human expert validation is highly recommended.*
436
  </p>
437
+ <p style="font-size: 0.8em; color: #777;'>
438
  Report generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
439
  </p>
440
  </div>