shoom013 commited on
Commit
5b0a950
1 Parent(s): 36a46fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -37,6 +37,7 @@ top_p=0.8
37
  frequency_penalty=0.0
38
  presence_penalty=0.15
39
  jezik = "srpski"
 
40
 
41
  system_sr = "Zoveš se U-Chat AI asistent i pomažeš korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem, upareno sa dodatnima saznanjima. Na osnovu toga napiši korisniku kratak i ljubazan odgovor koji kompletira njegov zahtev ili mu daje odgovor na pitanje. "
42
  # " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
@@ -75,22 +76,36 @@ Settings.llm = HuggingFaceInferenceAPI(model_name="mistralai/Mistral-Nemo-Instru
75
  # "BAAI/bge-m3"
76
  Settings.embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
77
  #documents = [Document(text="Indian parliament elections happened in April-May 2024. BJP Party won."),
78
- # Document(text="Indian parliament elections happened in April-May 2021. XYZ Party won."),
79
- # Document(text="Indian parliament elections happened in 2020. ABC Party won."),
80
  # ]
81
  #index = VectorStoreIndex.from_documents(
82
  # documents,
83
  #)
84
  vector_store = ChromaVectorStore(chroma_collection=collection)
85
  index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model)
86
- query_engine = index.as_query_engine()
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  def upload_file(filepath):
89
  documents = SimpleDirectoryReader(filepath).load_data()
90
  index = VectorStoreIndex.from_documents(documents)
91
- query_engine = index.as_query_engine()
 
92
  return filepath
93
 
 
 
 
 
94
  def rag(input_text, jezik, file):
95
  if (file):
96
  # documents = []
@@ -131,16 +146,20 @@ def rag(input_text, jezik, file):
131
  Settings.llm.system_prompt = system_sr + "Call centar telefon je 12755 za Crnu Goru, 0800 31111 za BIH, 070 700 700 u Sloveniji, 19900 u Srbiji, 095 1000 444 za hrvatske korisnike."
132
  if (o_jezik!='N/A'):
133
  input_text += " - odgovori " + o_jezik + "."
134
- query_engine = index.as_query_engine()
135
- return query_engine.query(input_text)
136
 
137
  iface = gr.Interface(fn=rag, inputs=[gr.Textbox(label="Pitanje:", lines=6),
138
  gr.Dropdown(["slovenski", "hrvatski", "srpski", "makedonski", "Eksperimentalna opcija"], value="srpski", label="Jezik", info="N/A"),
139
- gr.File()],
 
 
140
  outputs=[gr.Textbox(label="Odgovor:", lines=6)],
141
  title="Kako Vam mogu pomoći?",
142
- description= "UChat"
143
  )
 
 
144
 
145
  #with gr.Blocks() as iface:
146
  # gr.Markdown("Uchat")
 
37
  frequency_penalty=0.0
38
  presence_penalty=0.15
39
  jezik = "srpski"
40
+ cs = "s0"
41
 
42
  system_sr = "Zoveš se U-Chat AI asistent i pomažeš korisniku usluga kompanije United Group. Korisnik postavlja pitanje ili problem, upareno sa dodatnima saznanjima. Na osnovu toga napiši korisniku kratak i ljubazan odgovor koji kompletira njegov zahtev ili mu daje odgovor na pitanje. "
43
  # " Ako ne znaš odgovor, reci da ne znaš, ne izmišljaj ga."
 
76
  # "BAAI/bge-m3"
77
  Settings.embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
78
  #documents = [Document(text="Indian parliament elections happened in April-May 2024. BJP Party won."),
 
 
79
  # ]
80
  #index = VectorStoreIndex.from_documents(
81
  # documents,
82
  #)
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
+ similarity_top_k=3,
87
+ vector_store_query_mode="default",
88
+ # filters=MetadataFilters(
89
+ # filters=[
90
+ # ExactMatchFilter(key="state", value=cs),
91
+ # ]
92
+ # ),
93
+ alpha=None,
94
+ doc_ids=None,
95
+ ))
96
+ chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
97
 
98
  def upload_file(filepath):
99
  documents = SimpleDirectoryReader(filepath).load_data()
100
  index = VectorStoreIndex.from_documents(documents)
101
+ #query_engine = index.as_query_engine()
102
+ chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
103
  return filepath
104
 
105
+ def resetChat():
106
+ chat_engine.reset()
107
+ return True
108
+
109
  def rag(input_text, jezik, file):
110
  if (file):
111
  # documents = []
 
146
  Settings.llm.system_prompt = system_sr + "Call centar telefon je 12755 za Crnu Goru, 0800 31111 za BIH, 070 700 700 u Sloveniji, 19900 u Srbiji, 095 1000 444 za hrvatske korisnike."
147
  if (o_jezik!='N/A'):
148
  input_text += " - odgovori " + o_jezik + "."
149
+ # return query_engine.query(input_text)
150
+ return chat_engine.chat(input_text)
151
 
152
  iface = gr.Interface(fn=rag, inputs=[gr.Textbox(label="Pitanje:", lines=6),
153
  gr.Dropdown(["slovenski", "hrvatski", "srpski", "makedonski", "Eksperimentalna opcija"], value="srpski", label="Jezik", info="N/A"),
154
+ gr.File(),
155
+ b=gr.Button(label="Resetuj razgovor")
156
+ ],
157
  outputs=[gr.Textbox(label="Odgovor:", lines=6)],
158
  title="Kako Vam mogu pomoći?",
159
+ description="UChat"
160
  )
161
+ b.click(resetChat, b)
162
+
163
 
164
  #with gr.Blocks() as iface:
165
  # gr.Markdown("Uchat")