Spaces:
Build error
Build error
Commit ·
4eac2a7
1
Parent(s): 260a0fa
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,24 @@
|
|
| 1 |
-
# Import necessary libraries
|
| 2 |
import gradio as gr
|
| 3 |
import openai
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Initialize the conversation history
|
| 6 |
conversation_history = [
|
| 7 |
{
|
| 8 |
"role": "system",
|
| 9 |
-
"content": "Your name is Joe Chip, a world class poker player.
|
| 10 |
-
"If you need more context ask for it."
|
| 11 |
-
" Make sure you know what the effective stack is and whether its a cash game or mtt"
|
| 12 |
-
"Concentrate more on GTO play rather than exploiting other players."
|
| 13 |
-
"Consider blockers when applicable"
|
| 14 |
-
"Always discuss how to play your range, not just the hand in question"
|
| 15 |
-
"Remember to keep your answers brief"
|
| 16 |
-
"Only answer questions on poker topics"
|
| 17 |
}
|
| 18 |
]
|
| 19 |
|
| 20 |
-
# Function to setup OpenAI with the provided api_key
|
| 21 |
def setup_openai(api_key):
|
| 22 |
openai.api_key = api_key
|
| 23 |
return "API Key Set Successfully!"
|
| 24 |
|
| 25 |
-
# Function to interact with Joe
|
| 26 |
def ask_joe(api_key, text):
|
| 27 |
-
#
|
| 28 |
setup_openai(api_key)
|
| 29 |
|
| 30 |
# Add the user's message to the conversation history
|
|
@@ -49,15 +43,13 @@ def ask_joe(api_key, text):
|
|
| 49 |
"role": "assistant",
|
| 50 |
"content": model_message
|
| 51 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
# Return the model's response
|
| 54 |
return model_message
|
| 55 |
|
| 56 |
-
|
| 57 |
-
iface = gr.Interface(fn=ask_joe,
|
| 58 |
-
inputs=[gr.inputs.Textbox(lines=1, label="Enter OpenAI API Key"), gr.inputs.Textbox(lines=2, label="Ask your question here. More details = Better results")],
|
| 59 |
-
outputs=gr.outputs.Textbox(label="Joe's Response")
|
| 60 |
-
)
|
| 61 |
|
| 62 |
-
# Launch the Gradio Interface
|
| 63 |
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
# Initialize the logger with level INFO
|
| 6 |
+
logging.basicConfig(filename='conversation_history.log', level=logging.INFO)
|
| 7 |
|
| 8 |
# Initialize the conversation history
|
| 9 |
conversation_history = [
|
| 10 |
{
|
| 11 |
"role": "system",
|
| 12 |
+
"content": "Your name is Joe Chip, a world class poker player..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
]
|
| 15 |
|
|
|
|
| 16 |
def setup_openai(api_key):
|
| 17 |
openai.api_key = api_key
|
| 18 |
return "API Key Set Successfully!"
|
| 19 |
|
|
|
|
| 20 |
def ask_joe(api_key, text):
|
| 21 |
+
# set up the api_key
|
| 22 |
setup_openai(api_key)
|
| 23 |
|
| 24 |
# Add the user's message to the conversation history
|
|
|
|
| 43 |
"role": "assistant",
|
| 44 |
"content": model_message
|
| 45 |
})
|
| 46 |
+
|
| 47 |
+
# Log the conversation history
|
| 48 |
+
logging.info(f'User: {text}')
|
| 49 |
+
logging.info(f'AI: {model_message}')
|
| 50 |
|
|
|
|
| 51 |
return model_message
|
| 52 |
|
| 53 |
+
iface = gr.Interface(fn=ask_joe, inputs=[gr.inputs.Textbox(label="OpenAI API Key"), gr.inputs.Textbox(label="Your question")], outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
|
|
|
| 55 |
iface.launch()
|