Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import os
|
3 |
import openai
|
4 |
import gradio as gr
|
@@ -6,9 +5,12 @@ from dotenv import load_dotenv
|
|
6 |
|
7 |
# Load API key from .env file
|
8 |
load_dotenv()
|
9 |
-
api_key = os.getenv("
|
|
|
|
|
|
|
10 |
|
11 |
-
# Set up OpenAI
|
12 |
openai.api_key = api_key
|
13 |
|
14 |
# Define chatbot function
|
@@ -18,7 +20,7 @@ def python_tutor_bot(user_input):
|
|
18 |
|
19 |
# Create a completion request
|
20 |
response = openai.ChatCompletion.create(
|
21 |
-
model="gpt-
|
22 |
messages=[
|
23 |
{
|
24 |
"role": "system",
|
@@ -62,19 +64,16 @@ def python_tutor_bot(user_input):
|
|
62 |
# Return chatbot response
|
63 |
return response["choices"][0]["message"]["content"]
|
64 |
|
65 |
-
# Create Gradio chat interface
|
66 |
chatbot_ui = gr.Interface(
|
67 |
fn=python_tutor_bot,
|
68 |
inputs=gr.Textbox(lines=3, placeholder="Ask me anything about Python..."),
|
69 |
outputs=gr.Textbox(),
|
70 |
title="Python Tutor Bot",
|
71 |
-
description="A friendly Python tutor bot to help you learn and troubleshoot Python. Ask any question!"
|
72 |
-
|
73 |
)
|
74 |
|
75 |
# Launch Gradio UI
|
76 |
-
#chatbot_ui.launch(share=True)
|
77 |
-
|
78 |
-
|
79 |
if __name__ == "__main__":
|
80 |
chatbot_ui.launch(share=True)
|
|
|
|
|
1 |
import os
|
2 |
import openai
|
3 |
import gradio as gr
|
|
|
5 |
|
6 |
# Load API key from .env file
|
7 |
load_dotenv()
|
8 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
9 |
+
|
10 |
+
if not api_key:
|
11 |
+
raise ValueError("API Key not found! Ensure you have added OPENAI_API_KEY in your .env file.")
|
12 |
|
13 |
+
# Set up OpenAI API Key
|
14 |
openai.api_key = api_key
|
15 |
|
16 |
# Define chatbot function
|
|
|
20 |
|
21 |
# Create a completion request
|
22 |
response = openai.ChatCompletion.create(
|
23 |
+
model="gpt-4o-mini",
|
24 |
messages=[
|
25 |
{
|
26 |
"role": "system",
|
|
|
64 |
# Return chatbot response
|
65 |
return response["choices"][0]["message"]["content"]
|
66 |
|
67 |
+
# Create Gradio chat interface with Submit Button
|
68 |
chatbot_ui = gr.Interface(
|
69 |
fn=python_tutor_bot,
|
70 |
inputs=gr.Textbox(lines=3, placeholder="Ask me anything about Python..."),
|
71 |
outputs=gr.Textbox(),
|
72 |
title="Python Tutor Bot",
|
73 |
+
description="A friendly Python tutor bot to help you learn and troubleshoot Python. Ask any question!"
|
74 |
+
|
75 |
)
|
76 |
|
77 |
# Launch Gradio UI
|
|
|
|
|
|
|
78 |
if __name__ == "__main__":
|
79 |
chatbot_ui.launch(share=True)
|