Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|