Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from helper import get_together_api_key
|
3 |
from guardrail import is_safe
|
@@ -6,27 +8,11 @@ from together import Together
|
|
6 |
# Initialize Together client
|
7 |
client = Together(api_key=get_together_api_key())
|
8 |
|
9 |
-
#
|
10 |
def run_action(message, history):
|
11 |
-
global game_state, game_running # Access the global game state and game status
|
12 |
-
|
13 |
-
if not game_running:
|
14 |
-
return "The game has ended. Type 'restart the game' to play again."
|
15 |
-
|
16 |
-
if message.lower() == "start game":
|
17 |
-
return game_state["start"]
|
18 |
-
|
19 |
-
if message.lower() == "restart the game":
|
20 |
-
game_state = initialize_game_state()
|
21 |
-
return "Game restarted! " + game_state["start"]
|
22 |
-
|
23 |
-
if message.lower() == "exit":
|
24 |
-
game_running = False
|
25 |
-
return "The game has ended. Type 'restart the game' to play again."
|
26 |
-
|
27 |
system_prompt = """You are a financial assistant. You can only answer finance-related queries.
|
28 |
- Do not answer non-finance questions.
|
29 |
-
- Answer in 50 words
|
30 |
- Ensure responses adhere to the safety policy."""
|
31 |
|
32 |
messages = [{"role": "system", "content": system_prompt}]
|
@@ -49,7 +35,7 @@ def run_action(message, history):
|
|
49 |
|
50 |
return model_output.choices[0].message.content
|
51 |
|
52 |
-
|
53 |
def main_loop(message, history):
|
54 |
"""
|
55 |
Main loop for the chatbot to handle user input.
|
@@ -61,7 +47,6 @@ def main_loop(message, history):
|
|
61 |
# Generate and validate the response
|
62 |
return run_action(message, history)
|
63 |
|
64 |
-
|
65 |
# Gradio Chat Interface
|
66 |
demo = gr.ChatInterface(
|
67 |
main_loop,
|
@@ -82,4 +67,4 @@ demo = gr.ChatInterface(
|
|
82 |
)
|
83 |
|
84 |
# Launch the Gradio app
|
85 |
-
demo.launch(share=True, server_name="0.0.0.0")
|
|
|
1 |
+
# app.py (Finance Chatbot)
|
2 |
+
|
3 |
import gradio as gr
|
4 |
from helper import get_together_api_key
|
5 |
from guardrail import is_safe
|
|
|
8 |
# Initialize Together client
|
9 |
client = Together(api_key=get_together_api_key())
|
10 |
|
11 |
+
# Function to handle the chatbot's response to user queries
|
12 |
def run_action(message, history):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
system_prompt = """You are a financial assistant. You can only answer finance-related queries.
|
14 |
- Do not answer non-finance questions.
|
15 |
+
- Answer in 50 words.
|
16 |
- Ensure responses adhere to the safety policy."""
|
17 |
|
18 |
messages = [{"role": "system", "content": system_prompt}]
|
|
|
35 |
|
36 |
return model_output.choices[0].message.content
|
37 |
|
38 |
+
# Main loop for the chatbot to handle user input
|
39 |
def main_loop(message, history):
|
40 |
"""
|
41 |
Main loop for the chatbot to handle user input.
|
|
|
47 |
# Generate and validate the response
|
48 |
return run_action(message, history)
|
49 |
|
|
|
50 |
# Gradio Chat Interface
|
51 |
demo = gr.ChatInterface(
|
52 |
main_loop,
|
|
|
67 |
)
|
68 |
|
69 |
# Launch the Gradio app
|
70 |
+
demo.launch(share=True, server_name="0.0.0.0")
|