chuth commited on
Commit
2e54a02
·
verified ·
1 Parent(s): cea6169

Update model name

Browse files
Files changed (1) hide show
  1. app.py +47 -47
app.py CHANGED
@@ -1,48 +1,48 @@
1
- import gradio as gr
2
- from chat import get_response
3
-
4
- def clear_session():
5
- return "", []
6
-
7
- def add_query(chat_history, input):
8
- if not input:
9
- raise gr.Error("Please enter a question.")
10
- chat_history.append((input, None))
11
- return chat_history
12
-
13
- def response(history, query, model):
14
- chat_history = []
15
- for i in history:
16
- if i[0]:
17
- chat_history.append(i[0])
18
- if i[1]:
19
- chat_history.append(i[1])
20
-
21
- messages = [{"role": "user", "content": chat_history[0]}]
22
- for i in range(1, len(chat_history), 2):
23
- messages.append({"role": "assistant", "content": chat_history[i]})
24
- messages.append({"role": "user", "content": chat_history[i + 1]})
25
-
26
- res_msg = get_response(model, messages)
27
- history[-1] = (query, res_msg)
28
- return "", history
29
-
30
- demo = gr.Blocks(title= "Chatbot", theme="Soft")
31
- with demo:
32
- with gr.Column("Chatbot - Family Relationships"):
33
- model = gr.Radio(["gpt-3.5-turbo", "gpt-4-turbo", "ft:gpt-3.5-turbo-0125:personal::9hiINnam:ckpt-step-278"],
34
- label="model",
35
- info="Kindly choose a model before initiating the chat and clear the chat history before switching models. The last one is fine-tuned models.")
36
- chatbot = gr.Chatbot(value=[], elem_id='chatbot')
37
-
38
- text_input = gr.Textbox(
39
- show_label=False,
40
- placeholder="Ask me anything!",
41
- container=False)
42
-
43
- clear_btn = gr.Button("🧹 Clear")
44
- text_input.submit(add_query, inputs=[chatbot, text_input], outputs=[chatbot], concurrency_limit=1).\
45
- success(response, inputs=[chatbot, text_input, model], outputs=[text_input, chatbot])
46
- clear_btn.click(clear_session, inputs=[], outputs=[text_input, chatbot])
47
-
48
  demo.launch()
 
1
+ import gradio as gr
2
+ from chat import get_response
3
+
4
+ def clear_session():
5
+ return "", []
6
+
7
+ def add_query(chat_history, input):
8
+ if not input:
9
+ raise gr.Error("Please enter a question.")
10
+ chat_history.append((input, None))
11
+ return chat_history
12
+
13
+ def response(history, query, model):
14
+ chat_history = []
15
+ for i in history:
16
+ if i[0]:
17
+ chat_history.append(i[0])
18
+ if i[1]:
19
+ chat_history.append(i[1])
20
+
21
+ messages = [{"role": "user", "content": chat_history[0]}]
22
+ for i in range(1, len(chat_history), 2):
23
+ messages.append({"role": "assistant", "content": chat_history[i]})
24
+ messages.append({"role": "user", "content": chat_history[i + 1]})
25
+
26
+ res_msg = get_response(model, messages)
27
+ history[-1] = (query, res_msg)
28
+ return "", history
29
+
30
+ demo = gr.Blocks(title= "Chatbot", theme="Soft")
31
+ with demo:
32
+ with gr.Column("Chatbot - Family Relationships"):
33
+ model = gr.Radio(["gpt-3.5-turbo", "gpt-4-turbo", "ft:gpt-3.5-turbo-0125:personal::9hiINdK8"],
34
+ label="model",
35
+ info="Kindly choose a model before initiating the chat and clear the chat history before switching models. The last one is fine-tuned models.")
36
+ chatbot = gr.Chatbot(value=[], elem_id='chatbot')
37
+
38
+ text_input = gr.Textbox(
39
+ show_label=False,
40
+ placeholder="Ask me anything!",
41
+ container=False)
42
+
43
+ clear_btn = gr.Button("🧹 Clear")
44
+ text_input.submit(add_query, inputs=[chatbot, text_input], outputs=[chatbot], concurrency_limit=1).\
45
+ success(response, inputs=[chatbot, text_input, model], outputs=[text_input, chatbot])
46
+ clear_btn.click(clear_session, inputs=[], outputs=[text_input, chatbot])
47
+
48
  demo.launch()