Aishu-7 commited on
Commit
8ade7b7
·
verified ·
1 Parent(s): bc8f578

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,18 +1,35 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import huggingface_hub
4
- from sentence-transformers import SentenceTransformer
5
- import torch
6
  import numpy as np
7
  !pip install -q sentence-transformers
8
  from sentence_transformers import SentenceTransformer
9
  import torch
10
 
11
  with open("knowledge.txt", "r", encoding="utf-8") as file:
12
- # Read the entire contents of the file and store it in a variable
13
  knowledge_base = file.read()
14
 
15
- print(knowledge_base)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
18
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import huggingface_hub
 
 
4
  import numpy as np
5
  !pip install -q sentence-transformers
6
  from sentence_transformers import SentenceTransformer
7
  import torch
8
 
9
  with open("knowledge.txt", "r", encoding="utf-8") as file:
 
10
  knowledge_base = file.read()
11
 
12
+ def preprocess_text(text):
13
+ cleaned_text = text.strip()
14
+
15
+ chunks = cleaned_text.split("\n")
16
+
17
+ cleaned_chunks = []
18
+
19
+ for chunk in chunks:
20
+ stripped_chunk = chunk.strip()
21
+ if len (stripped_chunk)>0:
22
+ cleaned_chunks.append(stripped_chunk)
23
+
24
+
25
+ print(cleaned_chunks)
26
+
27
+ print (len(cleaned_chunks))
28
+
29
+ return cleaned_chunks
30
+
31
+
32
+ cleaned_chunks = preprocess_text(knowledge_base)
33
 
34
  client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
35