Spaces:

arjunanand13 commited on
Commit
af8f2bb
1 Parent(s): 7f2869e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -66
app.py CHANGED
@@ -9,6 +9,8 @@ import faiss
9
  import numpy as np
10
  from sentence_transformers import SentenceTransformer
11
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, BitsAndBytesConfig
 
 
12
 
13
  class DocumentRetrievalAndGeneration:
14
  def __init__(self, embedding_model_name, lm_model_id, data_folder):
@@ -58,8 +60,6 @@ class DocumentRetrievalAndGeneration:
58
  )
59
  return generate_text
60
 
61
-
62
-
63
  def generate_response_with_timeout(self, model_inputs):
64
  def target(future):
65
  if self.cancel_flag.is_set():
@@ -125,67 +125,4 @@ class DocumentRetrievalAndGeneration:
125
  return solution_text, content
126
 
127
  except TimeoutError:
128
- return "timeout", content
129
-
130
- if __name__ == "__main__":
131
- # Example usage
132
- embedding_model_name = 'flax-sentence-embeddings/all_datasets_v3_MiniLM-L12'
133
- lm_model_id = "mistralai/Mistral-7B-Instruct-v0.2"
134
- data_folder = 'sample_embedding_folder2'
135
-
136
- doc_retrieval_gen = DocumentRetrievalAndGeneration(embedding_model_name, lm_model_id, data_folder)
137
-
138
- def launch_interface():
139
- css_code = """
140
- .gradio-container {
141
- background-color: #daccdb;
142
- }
143
- /* Button styling for all buttons */
144
- button {
145
- background-color: #927fc7; /* Default color for all other buttons */
146
- color: black;
147
- border: 1px solid black;
148
- padding: 10px;
149
- margin-right: 10px;
150
- font-size: 16px; /* Increase font size */
151
- font-weight: bold; /* Make text bold */
152
- }
153
- """
154
- EXAMPLES = [
155
- "On which devices can the VIP and CSI2 modules operate simultaneously?",
156
- "I'm using Code Composer Studio 5.4.0.00091 and enabled FPv4SPD16 floating point support for CortexM4 in TDA2. However, after building the project, the .asm file shows --float_support=vfplib instead of FPv4SPD16. Why is this happening?",
157
- "Could you clarify the maximum number of cameras that can be connected simultaneously to the video input ports on the TDA2x SoC, considering it supports up to 10 multiplexed input ports and includes 3 dedicated video input modules?"
158
- ]
159
-
160
- file_path = "ticketNames.txt"
161
-
162
- with open(file_path, "r") as file:
163
- content = file.read()
164
- ticket_names = json.loads(content)
165
- dropdown = gr.Dropdown(label="Sample queries", choices=ticket_names)
166
-
167
- tab1 = gr.Interface(
168
- fn=doc_retrieval_gen.qa_infer_gradio,
169
- inputs=[gr.Textbox(label="QUERY", placeholder="Enter your query here")],
170
- allow_flagging='never',
171
- examples=EXAMPLES,
172
- cache_examples=False,
173
- outputs=[gr.Textbox(label="SOLUTION"), gr.Textbox(label="RELATED QUERIES")],
174
- css=css_code
175
- )
176
- tab2 = gr.Interface(
177
- fn=doc_retrieval_gen.qa_infer_gradio,
178
- inputs=[dropdown],
179
- allow_flagging='never',
180
- outputs=[gr.Textbox(label="SOLUTION"), gr.Textbox(label="RELATED QUERIES")],
181
- css=css_code
182
- )
183
-
184
- gr.TabbedInterface(
185
- [tab1, tab2],
186
- ["Textbox Input", "FAQs"],
187
- title="TI E2E FORUM",
188
- css=css_code
189
- ).launch(debug=True)
190
-
191
- launch_interface()
 
9
  import numpy as np
10
  from sentence_transformers import SentenceTransformer
11
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, BitsAndBytesConfig
12
+ from langchain.document_loaders import DirectoryLoader, TextLoader # Import these from langchain
13
+ from langchain.text_splitter import RecursiveCharacterTextSplitter # Import the text splitter
14
 
15
  class DocumentRetrievalAndGeneration:
16
  def __init__(self, embedding_model_name, lm_model_id, data_folder):
 
60
  )
61
  return generate_text
62
 
 
 
63
  def generate_response_with_timeout(self, model_inputs):
64
  def target(future):
65
  if self.cancel_flag.is_set():
 
125
  return solution_text, content
126
 
127
  except TimeoutError:
128
+ return "timeout", content