-
Notifications
You must be signed in to change notification settings - Fork 0
/
borusan.py
31 lines (25 loc) · 1.27 KB
/
borusan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from llama_index import VectorStoreIndex, ServiceContext, Document, SimpleDirectoryReader
from llama_index.llms import OpenAI
def main():
# Initialize session state for the index and query engine
if 'index' not in st.session_state or 'query_engine' not in st.session_state:
documents = SimpleDirectoryReader(
input_files=["Main_Data.pdf"]
).load_data()
document = Document(text="\n\n".join([doc.text for doc in documents]))
llm = OpenAI(model="gpt-3.5-turbo", temperature=0.2)
service_context = ServiceContext.from_defaults(
llm=llm, embed_model="local:BAAI/bge-large-en-v1.5"
)
st.session_state['index'] = VectorStoreIndex.from_documents([document], service_context=service_context)
st.session_state['query_engine'] = st.session_state['index'].as_query_engine(similarity_top_k=10)
st.title("Borusan AutoInsight")
user_query = st.text_input("Merak Ettiğiniz Model Hakkındaki Sorunuzu Giriniz:")
submit_button = st.button('Sor') # Add this line for the button
if submit_button and user_query:
response = st.session_state['query_engine'].query(user_query)
st.text("Yanıt:")
st.write(str(response))
if __name__ == "__main__":
main()