obaes commited on
Commit
e52448c
1 Parent(s): 8dcd4d9
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -6,28 +6,37 @@ import gradio as gr
6
  from gradio_pdf import PDF
7
  import os
8
 
9
- hfkey = os.getenv("HFKEY")
10
  api_key = 'Of59Qz8Enr4fVj11XoKLRkNHENULLpLt'
 
 
11
 
12
- llm = MistralAI(api_key=api_key, model="mistral-medium-latest")
13
  embed_model = MistralAIEmbedding(model_name='mistral-embed', api_key=api_key)
14
 
15
  Settings.llm = llm
16
  Settings.embed_model = embed_model
17
 
18
- def qa(question: str, doc: str) -> str:
 
 
 
 
19
  my_pdf = SimpleDirectoryReader(input_files=[doc]).load_data()
20
  my_pdf_index = VectorStoreIndex.from_documents(my_pdf)
21
  my_pdf_engine = my_pdf_index.as_query_engine()
22
  question = "repond en francais, " + question
23
  response = my_pdf_engine.query(question)
 
24
  return response
25
 
26
  demo = gr.Interface(
27
  qa,
28
- [gr.Textbox(label="Question"), PDF(label="Document")],
 
29
  gr.Textbox())
30
 
 
31
  if __name__ == "__main__":
32
  demo.launch(auth=("username", "password"))
33
 
 
6
  from gradio_pdf import PDF
7
  import os
8
 
9
+
10
  api_key = 'Of59Qz8Enr4fVj11XoKLRkNHENULLpLt'
11
+ my_list=['open-mistral-7b', 'open-mixtral-8x7b', 'mistral-small-latest','mistral-medium-latest','mistral-large-latest']
12
+ mdel= my_list[3]
13
 
14
+ llm = MistralAI(api_key=api_key, model=mdel)
15
  embed_model = MistralAIEmbedding(model_name='mistral-embed', api_key=api_key)
16
 
17
  Settings.llm = llm
18
  Settings.embed_model = embed_model
19
 
20
+ def qa(model: str, question: str, doc: str, mdel: str) -> str:
21
+ if mdel != model:
22
+ mdel= model
23
+ llm = MistralAI(api_key=api_key, model=mdel)
24
+
25
  my_pdf = SimpleDirectoryReader(input_files=[doc]).load_data()
26
  my_pdf_index = VectorStoreIndex.from_documents(my_pdf)
27
  my_pdf_engine = my_pdf_index.as_query_engine()
28
  question = "repond en francais, " + question
29
  response = my_pdf_engine.query(question)
30
+ #response = question + " " + str(response)
31
  return response
32
 
33
  demo = gr.Interface(
34
  qa,
35
+ [ gr.Dropdown(choices=my_list, label="model",value=mdel),
36
+ gr.Textbox(label="Question"), PDF(label="Document")],
37
  gr.Textbox())
38
 
39
+
40
  if __name__ == "__main__":
41
  demo.launch(auth=("username", "password"))
42