Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -83,6 +83,13 @@ Settings.embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/al
|
|
83 |
vector_store = ChromaVectorStore(chroma_collection=collection)
|
84 |
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
|
85 |
query_engine = index.as_query_engine()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
def rag(input_text, file):
|
87 |
if (file):
|
88 |
# documents = []
|
@@ -107,30 +114,24 @@ def rag(input_text, file):
|
|
107 |
query_engine = index.as_query_engine()
|
108 |
return query_engine.query(input_text)
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
with gr.Column(scale=1):
|
130 |
-
out = gr.Textbox(label="Odgovor:", lines=6)
|
131 |
-
sub = gr.Button("Pokreni")
|
132 |
-
|
133 |
-
u.upload(upload_file, u, file_out)
|
134 |
-
sub.click(rag, inp, out)
|
135 |
|
136 |
iface.launch()
|
|
|
83 |
vector_store = ChromaVectorStore(chroma_collection=collection)
|
84 |
index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
|
85 |
query_engine = index.as_query_engine()
|
86 |
+
|
87 |
+
def upload_file(filepath):
|
88 |
+
documents = SimpleDirectoryReader(filepath).load_data()
|
89 |
+
index = VectorStoreIndex.from_documents(documents)
|
90 |
+
query_engine = index.as_query_engine()
|
91 |
+
return filepath
|
92 |
+
|
93 |
def rag(input_text, file):
|
94 |
if (file):
|
95 |
# documents = []
|
|
|
114 |
query_engine = index.as_query_engine()
|
115 |
return query_engine.query(input_text)
|
116 |
|
117 |
+
iface = gr.Interface(fn=rag, inputs=[gr.Textbox(label="Pitanje:", lines=6), gr.File()],
|
118 |
+
outputs=[gr.Textbox(label="Odgovor:", lines=6)],
|
119 |
+
title="Kako Vam mogu pomoći?",
|
120 |
+
description= "UChat"
|
121 |
+
)
|
122 |
|
123 |
+
#with gr.Blocks() as iface:
|
124 |
+
# gr.Markdown("Uchat")
|
125 |
+
# file_out = gr.File()
|
126 |
+
# with gr.Row():
|
127 |
+
# with gr.Column(scale=1):
|
128 |
+
# inp = gr.Textbox(label="Pitanje:", lines=6)
|
129 |
+
# u = gr.UploadButton("Upload a file", file_count="single")
|
130 |
+
# with gr.Column(scale=1):
|
131 |
+
# out = gr.Textbox(label="Odgovor:", lines=6)
|
132 |
+
# sub = gr.Button("Pokreni")
|
133 |
+
#
|
134 |
+
# u.upload(upload_file, u, file_out)
|
135 |
+
# sub.click(rag, inp, out)
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
iface.launch()
|