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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -55
app.py CHANGED
@@ -1,56 +1,39 @@
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()
 
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
+ !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
8
+ !pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes
9
+
10
+ llm_chain = llm_chain_response()
11
+
12
+ def chat_with_mistral(user_input):
13
+ if not user_input:
14
+ return "The message is not be empty."
15
+ response = llm_chain.invoke({"query": user_input})
16
+ print(response)
17
+
18
+ print("---------------Response--------------")
19
+ print(get_response_value(response["result"]))
20
+ return get_response_value(response["result"])
21
+
22
+ def main():
23
+ # Initialize the database
24
+ create_db_from_files()
25
+
26
+ # Set up and launch the Gradio interface
27
+ iface = gr.Interface(
28
+ fn=chat_with_mistral,
29
+ inputs=gr.components.Textbox(label="Enter Your Message"),
30
+ outputs=gr.components.Markdown(label="ChatbotResponse"),
31
+ title="Resvu AI Chatbot",
32
+ description="Interact with the Resvu API via this chatbot. Enter a message and get a response.",
33
+ examples=["Hi, how are you", "Who are you?", "What services do you offer?", "How can I find out about upcoming community events?"],
34
+ allow_flagging="never"
35
+ )
36
+ iface.launch()
37
+
38
+ if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  main()