Update app.py
Browse files
app.py
CHANGED
|
@@ -45,28 +45,25 @@ def split_into_chunks(text, chunk_size=100):
|
|
| 45 |
|
| 46 |
return chunks
|
| 47 |
|
| 48 |
-
def semantic_search(query,
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
# Define Gradio interface
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=semantic_search,
|
| 60 |
inputs=[
|
| 61 |
gr.Textbox(lines=2, placeholder="Enter your query here..."),
|
| 62 |
-
gr.File(label="Upload a .txt file")
|
| 63 |
],
|
| 64 |
outputs="text",
|
| 65 |
title="Document Semantic Search",
|
| 66 |
-
description="Input a query and upload a document (.txt) to find the most semantically similar paragraphs or sentences."
|
| 67 |
-
examples=[
|
| 68 |
-
["Enter a sample query here...", None]
|
| 69 |
-
]
|
| 70 |
)
|
| 71 |
|
| 72 |
iface.launch()
|
|
|
|
| 45 |
|
| 46 |
return chunks
|
| 47 |
|
| 48 |
+
def semantic_search(query, file):
|
| 49 |
+
if file is not None:
|
| 50 |
+
document = file.read().decode('utf-8')
|
| 51 |
+
chunks = split_into_chunks(document)
|
| 52 |
+
response = query_similarity(query, chunks)
|
| 53 |
+
return format_output(response)
|
| 54 |
+
else:
|
| 55 |
+
return "Please upload a .txt file."
|
| 56 |
|
| 57 |
# Define Gradio interface
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=semantic_search,
|
| 60 |
inputs=[
|
| 61 |
gr.Textbox(lines=2, placeholder="Enter your query here..."),
|
| 62 |
+
gr.File(file_types=['txt'], label="Upload a .txt file")
|
| 63 |
],
|
| 64 |
outputs="text",
|
| 65 |
title="Document Semantic Search",
|
| 66 |
+
description="Input a query and upload a document (.txt) to find the most semantically similar paragraphs or sentences."
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
iface.launch()
|