aquibmoin commited on
Commit
8bb6871
1 Parent(s): 995f567

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
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, document):
49
- chunks = split_into_chunks(document)
50
- response = query_similarity(query, chunks)
51
- return format_output(response)
52
-
53
- def read_file(file):
54
- text = file.read().decode('utf-8')
55
- return text
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()