Zahid0123 commited on
Commit
649d931
·
verified ·
1 Parent(s): 7b26e18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,5 +1,4 @@
1
- # app.py - FULLY WORKING WITH GLOBAL GROQ CLIENT
2
- import os
3
  import re
4
  import logging
5
  import tempfile
@@ -12,7 +11,9 @@ import faiss
12
  import gradio as gr
13
  from gtts import gTTS
14
 
 
15
  # Safe Groq import
 
16
  try:
17
  from groq import Groq
18
  GROQ_OK = True
@@ -23,7 +24,7 @@ logging.basicConfig(level=logging.INFO)
23
  logger = logging.getLogger(__name__)
24
 
25
  # ===============================
26
- # 🔑 HARDCODE YOUR GROQ API KEY HERE (GLOBAL)
27
  # ===============================
28
  GROQ_API_KEY = "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"
29
  groq_client = None
@@ -37,6 +38,9 @@ if GROQ_OK:
37
  groq_client = None
38
  print("DEBUG → Groq initialization error:", e)
39
 
 
 
 
40
  class AgenticRAGAgent:
41
  def __init__(self):
42
  self.chunks = []
@@ -92,7 +96,7 @@ class AgenticRAGAgent:
92
  content = file.read() if hasattr(file, 'read') else open(file.name, 'rb').read()
93
  with open(dest, "wb") as f:
94
  f.write(content)
95
- except Exception as e:
96
  continue
97
 
98
  text = ""
@@ -124,7 +128,7 @@ class AgenticRAGAgent:
124
  return f"Loaded {count} PDF(s) → {len(all_chunks)} chunks ready!"
125
 
126
  def ask(self, question: str, history: List):
127
- global groq_client # use global client
128
  if not question.strip():
129
  return history, None
130
 
@@ -165,7 +169,9 @@ class AgenticRAGAgent:
165
  history.append([question, reply])
166
  return history, self.generate_voice(reply)
167
 
168
- # YOUR ORIGINAL UI
 
 
169
  def create_interface():
170
  agent = AgenticRAGAgent()
171
 
 
1
+ # app.py - FULLY WORKING END-TO-END (Hardcoded Groq API Key)
 
2
  import re
3
  import logging
4
  import tempfile
 
11
  import gradio as gr
12
  from gtts import gTTS
13
 
14
+ # ===============================
15
  # Safe Groq import
16
+ # ===============================
17
  try:
18
  from groq import Groq
19
  GROQ_OK = True
 
24
  logger = logging.getLogger(__name__)
25
 
26
  # ===============================
27
+ # 🔑 Hardcoded Groq API Key (GLOBAL)
28
  # ===============================
29
  GROQ_API_KEY = "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"
30
  groq_client = None
 
38
  groq_client = None
39
  print("DEBUG → Groq initialization error:", e)
40
 
41
+ # ===============================
42
+ # Agentic RAG Agent
43
+ # ===============================
44
  class AgenticRAGAgent:
45
  def __init__(self):
46
  self.chunks = []
 
96
  content = file.read() if hasattr(file, 'read') else open(file.name, 'rb').read()
97
  with open(dest, "wb") as f:
98
  f.write(content)
99
+ except Exception:
100
  continue
101
 
102
  text = ""
 
128
  return f"Loaded {count} PDF(s) → {len(all_chunks)} chunks ready!"
129
 
130
  def ask(self, question: str, history: List):
131
+ global groq_client
132
  if not question.strip():
133
  return history, None
134
 
 
169
  history.append([question, reply])
170
  return history, self.generate_voice(reply)
171
 
172
+ # ===============================
173
+ # Gradio Interface
174
+ # ===============================
175
  def create_interface():
176
  agent = AgenticRAGAgent()
177