emar commited on
Commit
f082418
1 Parent(s): 5d785a7
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
+ from llama_index.core import (
5
+ VectorStoreIndex,
6
+ SimpleDirectoryReader,
7
+ StorageContext,
8
+ load_index_from_storage, Settings,
9
+ )
10
+ from llama_index.llms.ollama import Ollama
11
+
12
+
13
+ # Path to your local corpus directory
14
+ PERSIST_DIR = './storage'
15
+
16
+ # Configure the settings
17
+ Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-base-en-v1.5")
18
+ Settings.llm = Ollama(model="llama3", request_timeout=360.0)
19
+
20
+ # Load the existing index
21
+ storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR)
22
+ index = load_index_from_storage(storage_context)
23
+
24
+ query_engine = index.as_query_engine()
25
+
26
+ def chatbot_response(user_input):
27
+ response = query_engine.query(user_input)
28
+ return str(response)
29
+
30
+ # Create a Gradio interface
31
+ interface = gr.Interface(fn=chatbot_response, inputs="text", outputs="text", title="Chatbot")
32
+
33
+ # Launch the interface
34
+ if __name__ == "__main__":
35
+ interface.launch()