DasperMansfield commited on
Commit
0f227f1
·
verified ·
1 Parent(s): e61d737

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -9
app.py CHANGED
@@ -1,4 +1,20 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Define the main function for the app
4
  def main_function(purpose, help_text, export_text, extra_menu_item, chat_input, tts_input, script_input):
@@ -43,12 +59,78 @@ with gr.Blocks() as demo:
43
  outputs=[purpose_output, help_output, export_output, extra_menu_output, chat_output, tts_output, script_output]
44
  )
45
 
46
- # Launch the app with custom colors
47
- demo.launch(css="""
48
- .gr-button-primary {
49
- background-color: #4CAF50; /* Green */
50
- color: white;
51
- }
52
- .gr-textbox {
53
- background-color: #f0f0f0; /* Light Gray */
54
- color: #333;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from gradio import ChatMessage
3
+ import time
4
+
5
+ def slow_echo(message, history):
6
+ for i in range(len(message)):
7
+ time.sleep(0.05)
8
+ yield "You typed: " + message[: i + 1]
9
+
10
+ demo = gr.ChatInterface(
11
+ slow_echo,
12
+ type="messages",
13
+ flagging_mode="manual",
14
+ flagging_options=["Like", "Spam", "Inappropriate", "Other"],
15
+ save_history=True,
16
+ )
17
+
18
 
19
  # Define the main function for the app
20
  def main_function(purpose, help_text, export_text, extra_menu_item, chat_input, tts_input, script_input):
 
59
  outputs=[purpose_output, help_output, export_output, extra_menu_output, chat_output, tts_output, script_output]
60
  )
61
 
62
+ def generate_response(history):
63
+ history.append(
64
+ ChatMessage(
65
+ role="user", content="What is the weather in San Francisco right now?"
66
+ )
67
+ )
68
+ yield history
69
+ time.sleep(0.25)
70
+ history.append(
71
+ ChatMessage(
72
+ role="assistant",
73
+ content="In order to find the current weather in San Francisco, I will need to use my weather tool.",
74
+ )
75
+ )
76
+ yield history
77
+ time.sleep(0.25)
78
+
79
+ history.append(
80
+ ChatMessage(
81
+ role="assistant",
82
+ content="API Error when connecting to weather service.",
83
+ metadata={"title": "💥 Error using tool 'Weather'"},
84
+ )
85
+ )
86
+ yield history
87
+ time.sleep(0.25)
88
+
89
+ history.append(
90
+ ChatMessage(
91
+ role="assistant",
92
+ content="I will try again",
93
+ )
94
+ )
95
+ yield history
96
+ time.sleep(0.25)
97
+
98
+ history.append(
99
+ ChatMessage(
100
+ role="assistant",
101
+ content="Weather 72 degrees Fahrenheit with 20% chance of rain.",
102
+ metadata={"title": "🛠️ Used tool 'Weather'"},
103
+ )
104
+ )
105
+ yield history
106
+ time.sleep(0.25)
107
+
108
+ history.append(
109
+ ChatMessage(
110
+ role="assistant",
111
+ content="Now that the API succeeded I can complete my task.",
112
+ )
113
+ )
114
+ yield history
115
+ time.sleep(0.25)
116
+
117
+ history.append(
118
+ ChatMessage(
119
+ role="assistant",
120
+ content="It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!",
121
+ )
122
+ )
123
+ yield history
124
+
125
+ def like(evt: gr.LikeData):
126
+ print("User liked the response")
127
+ print(evt.index, evt.liked, evt.value)
128
+
129
+ with gr.Blocks() as demo:
130
+ chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True)
131
+ button = gr.Button("Get San Francisco Weather")
132
+ button.click(generate_response, chatbot, chatbot)
133
+ chatbot.like(like)
134
+
135
+ if __name__ == "__main__":
136
+ demo.launch()