Upload app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from langchain.vectorstores import Chroma
|
|
7 |
import openai
|
8 |
import streamlit as st
|
9 |
import gradio as gr
|
|
|
10 |
|
11 |
openai.api_key = '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'
|
12 |
|
@@ -73,12 +74,17 @@ def save_in_DB(splitted_text):
|
|
73 |
return db
|
74 |
|
75 |
|
76 |
-
def query(query_text):
|
77 |
st.title('RAG system')
|
78 |
|
79 |
# query_text = st.text_input("Enter your question", "Cynthia W. Harris is a citizen of which state?", key="question")
|
80 |
-
docs = db.similarity_search(query_text)
|
81 |
print("len(docs)", len(docs))
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
# Store the first 10 results as context
|
84 |
context = '\n\n'.join([doc.page_content for doc in docs[:5]])
|
@@ -102,7 +108,7 @@ def query(query_text):
|
|
102 |
# Return the generated answer
|
103 |
st.subheader("Answer:")
|
104 |
st.write(predicted)
|
105 |
-
return predicted
|
106 |
|
107 |
|
108 |
|
@@ -116,7 +122,14 @@ def run():
|
|
116 |
db = save_in_DB(splitted_text)
|
117 |
print("type db", type(db))
|
118 |
|
119 |
-
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
demo.launch()
|
122 |
# query(db)
|
|
|
7 |
import openai
|
8 |
import streamlit as st
|
9 |
import gradio as gr
|
10 |
+
from gradio.components import Textbox, Slider
|
11 |
|
12 |
openai.api_key = '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'
|
13 |
|
|
|
74 |
return db
|
75 |
|
76 |
|
77 |
+
def query(query_text, num_docs):
|
78 |
st.title('RAG system')
|
79 |
|
80 |
# query_text = st.text_input("Enter your question", "Cynthia W. Harris is a citizen of which state?", key="question")
|
81 |
+
docs = db.similarity_search(query_text, k=num_docs)
|
82 |
print("len(docs)", len(docs))
|
83 |
+
# print each docs .page_content with klar abgrenzen
|
84 |
+
for doc in docs:
|
85 |
+
print("doc", doc.page_content)
|
86 |
+
print()
|
87 |
+
print()
|
88 |
|
89 |
# Store the first 10 results as context
|
90 |
context = '\n\n'.join([doc.page_content for doc in docs[:5]])
|
|
|
108 |
# Return the generated answer
|
109 |
st.subheader("Answer:")
|
110 |
st.write(predicted)
|
111 |
+
return predicted
|
112 |
|
113 |
|
114 |
|
|
|
122 |
db = save_in_DB(splitted_text)
|
123 |
print("type db", type(db))
|
124 |
|
125 |
+
demo = gr.Interface(
|
126 |
+
fn=query,
|
127 |
+
inputs=[
|
128 |
+
Textbox(lines=1, placeholder="Type your question here...", label="Question"),
|
129 |
+
Slider(minimum=1, maximum=20, default=4, step=1, label="Number of Documents in Context")
|
130 |
+
],
|
131 |
+
outputs="text"
|
132 |
+
)
|
133 |
|
134 |
demo.launch()
|
135 |
# query(db)
|