thinh111 commited on
Commit
57e6440
β€’
1 Parent(s): b6fb1b8

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -40
app.py CHANGED
@@ -1,41 +1,56 @@
1
- import subprocess
2
- import sys
3
- import gradio as gr
4
- from model import llm_chain_response, get_response_value
5
- from process_documents import create_db_from_files
6
-
7
- def run_setup():
8
- subprocess.check_call([sys.executable, "setup.py"])
9
-
10
- # Run the setup script
11
- run_setup()
12
- llm_chain = llm_chain_response()
13
-
14
- def chat_with_mistral(user_input):
15
- if not user_input:
16
- return "The message is not be empty."
17
- response = llm_chain.invoke({"query": user_input})
18
- print(response)
19
-
20
- print("---------------Response--------------")
21
- print(get_response_value(response["result"]))
22
- return get_response_value(response["result"])
23
-
24
- def main():
25
- # Initialize the database
26
- create_db_from_files()
27
-
28
- # Set up and launch the Gradio interface
29
- iface = gr.Interface(
30
- fn=chat_with_mistral,
31
- inputs=gr.components.Textbox(label="Enter Your Message"),
32
- outputs=gr.components.Markdown(label="ChatbotResponse"),
33
- title="Resvu AI Chatbot",
34
- description="Interact with the Resvu API via this chatbot. Enter a message and get a response.",
35
- examples=["Hi, how are you", "Who are you?", "What services do you offer?", "How can I find out about upcoming community events?"],
36
- allow_flagging="never"
37
- )
38
- iface.launch()
39
-
40
- if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  main()
 
1
+ import subprocess
2
+ import sys
3
+ import gradio as gr
4
+ from model import llm_chain_response, get_response_value
5
+ from process_documents import create_db_from_files
6
+
7
+ def install(package):
8
+ subprocess.check_call([sys.executable, "-m", "pip", "install", package])
9
+
10
+ # List of packages to install
11
+ packages = [
12
+ "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git",
13
+ "--no-deps xformers",
14
+ "trl<0.9.0",
15
+ "peft",
16
+ "accelerate",
17
+ "bitsandbytes"
18
+ ]
19
+
20
+ # Install packages
21
+ for package in packages:
22
+ try:
23
+ install(package)
24
+ except Exception as e:
25
+ print(f"Failed to install {package}: {e}")
26
+
27
+ llm_chain = llm_chain_response()
28
+
29
+ def chat_with_mistral(user_input):
30
+ if not user_input:
31
+ return "The message is not be empty."
32
+ response = llm_chain.invoke({"query": user_input})
33
+ print(response)
34
+
35
+ print("---------------Response--------------")
36
+ print(get_response_value(response["result"]))
37
+ return get_response_value(response["result"])
38
+
39
+ def main():
40
+ # Initialize the database
41
+ create_db_from_files()
42
+
43
+ # Set up and launch the Gradio interface
44
+ iface = gr.Interface(
45
+ fn=chat_with_mistral,
46
+ inputs=gr.components.Textbox(label="Enter Your Message"),
47
+ outputs=gr.components.Markdown(label="ChatbotResponse"),
48
+ title="Resvu AI Chatbot",
49
+ description="Interact with the Resvu API via this chatbot. Enter a message and get a response.",
50
+ examples=["Hi, how are you", "Who are you?", "What services do you offer?", "How can I find out about upcoming community events?"],
51
+ allow_flagging="never"
52
+ )
53
+ iface.launch()
54
+
55
+ if __name__ == "__main__":
56
  main()