CosmickVisions commited on
Commit
3a24858
·
verified ·
1 Parent(s): a490b01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -5,7 +5,7 @@ import tempfile
5
  import uuid
6
  from dotenv import load_dotenv
7
  from langchain_community.vectorstores import FAISS
8
- from langchain_community.embeddings import HuggingFaceInstructEmbeddings
9
  from langchain.text_splitter import RecursiveCharacterTextSplitter
10
  import fitz # PyMuPDF
11
  import base64
@@ -25,21 +25,13 @@ client = groq.Client(api_key=os.getenv("GROQ_TECH_API_KEY"))
25
 
26
  # Initialize embeddings with error handling
27
  try:
28
- # Force CPU usage for embeddings
29
- embeddings = HuggingFaceInstructEmbeddings(
30
- model_name="hkunlp/instructor-base",
31
- model_kwargs={"device": "cpu"} # Force CPU usage
32
  )
33
  except Exception as e:
34
- print(f"Warning: Failed to load primary embeddings model: {e}")
35
- try:
36
- embeddings = HuggingFaceInstructEmbeddings(
37
- model_name="all-MiniLM-L6-v2",
38
- model_kwargs={"device": "cpu"} # Force CPU usage
39
- )
40
- except Exception as e:
41
- print(f"Warning: Failed to load fallback embeddings model: {e}")
42
- embeddings = None
43
 
44
  # Directory to store FAISS indexes with better naming
45
  FAISS_INDEX_DIR = "faiss_indexes_tech_cpu"
@@ -802,6 +794,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
802
  with gr.Row(elem_classes="code-analysis"):
803
  with gr.Column(scale=1, elem_classes="analysis-card"):
804
  gr.Markdown("### Code Metrics", elem_classes="card-title")
 
805
  with gr.Row(elem_classes="metric-grid"):
806
  gr.Markdown("**Language:**", elem_classes="metric-label")
807
  gr.Markdown("-", elem_classes="metric-value", elem_id="language-metric")
@@ -833,8 +826,8 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
833
  chatbot = gr.Chatbot(
834
  height=400,
835
  elem_classes="chat-messages",
836
- bubble_full_width=False,
837
- show_copy_button=True
838
  )
839
 
840
  with gr.Row(elem_classes="chat-input-area"):
 
5
  import uuid
6
  from dotenv import load_dotenv
7
  from langchain_community.vectorstores import FAISS
8
+ from langchain_community.embeddings import SentenceTransformerEmbeddings
9
  from langchain.text_splitter import RecursiveCharacterTextSplitter
10
  import fitz # PyMuPDF
11
  import base64
 
25
 
26
  # Initialize embeddings with error handling
27
  try:
28
+ embeddings = SentenceTransformerEmbeddings(
29
+ model_name="all-MiniLM-L6-v2",
30
+ model_kwargs={"device": "cpu"}
 
31
  )
32
  except Exception as e:
33
+ print(f"Error loading embeddings: {e}")
34
+ embeddings = None
 
 
 
 
 
 
 
35
 
36
  # Directory to store FAISS indexes with better naming
37
  FAISS_INDEX_DIR = "faiss_indexes_tech_cpu"
 
794
  with gr.Row(elem_classes="code-analysis"):
795
  with gr.Column(scale=1, elem_classes="analysis-card"):
796
  gr.Markdown("### Code Metrics", elem_classes="card-title")
797
+ code_metrics = gr.Markdown("Upload code to see metrics", elem_id="code-metrics")
798
  with gr.Row(elem_classes="metric-grid"):
799
  gr.Markdown("**Language:**", elem_classes="metric-label")
800
  gr.Markdown("-", elem_classes="metric-value", elem_id="language-metric")
 
826
  chatbot = gr.Chatbot(
827
  height=400,
828
  elem_classes="chat-messages",
829
+ show_copy_button=True,
830
+ type="messages"
831
  )
832
 
833
  with gr.Row(elem_classes="chat-input-area"):