TejAndrewsACC commited on
Commit
f338432
·
verified ·
1 Parent(s): 620ea30

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client
3
+
4
+ client = Client("TejAndrewsACC/Z3ta")
5
+
6
+ context = ""
7
+
8
+ system_instructions = (
9
+ "None"
10
+ )
11
+
12
+ def chat_function(message, history):
13
+ global context
14
+
15
+ modified_input = (
16
+ f"System Instructions: {system_instructions}\n"
17
+ f"Previous Context: {context}\n"
18
+ f"User Input: {message}"
19
+ )
20
+
21
+ try:
22
+ response = client.predict(
23
+ message=modified_input,
24
+ api_name="/chat_function"
25
+ )
26
+
27
+ context += f"User: {message}\nAI: {response}\n"
28
+
29
+ history.append((message, response))
30
+
31
+ return response, history
32
+
33
+ except Exception as e:
34
+ return f"Error: {e}", history
35
+
36
+ with gr.Blocks(theme=gr.themes.Glass()) as demo:
37
+ chatbot = gr.Chatbot()
38
+ msg = gr.Textbox(placeholder="Type something...")
39
+ clear = gr.ClearButton([msg, chatbot])
40
+
41
+ msg.submit(chat_function, [msg, chatbot], [msg, chatbot])
42
+
43
+ demo.launch()