Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,11 @@ import openai
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Use
|
| 7 |
-
openai.api_key = os.environ.get("
|
| 8 |
-
|
| 9 |
-
|
| 10 |
openai.api_base = "https://api.groq.com/openai/v1"
|
| 11 |
|
|
|
|
| 12 |
def tutor_chatbot(subject, question, chat_history=[]):
|
| 13 |
try:
|
| 14 |
messages = [
|
|
@@ -17,7 +16,7 @@ def tutor_chatbot(subject, question, chat_history=[]):
|
|
| 17 |
]
|
| 18 |
|
| 19 |
response = openai.ChatCompletion.create(
|
| 20 |
-
model="llama3-8b-8192", #
|
| 21 |
messages=messages,
|
| 22 |
temperature=0.5,
|
| 23 |
max_tokens=800,
|
|
@@ -28,13 +27,16 @@ def tutor_chatbot(subject, question, chat_history=[]):
|
|
| 28 |
except Exception as e:
|
| 29 |
return chat_history + [("Error", str(e))]
|
| 30 |
|
|
|
|
| 31 |
subjects = ["Math", "Physics", "Biology", "CSS Exam", "Computer Science", "History"]
|
| 32 |
|
|
|
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
gr.Markdown("## 📚 AI Educational Tutor Chatbot (Groq API)")
|
|
|
|
| 35 |
subject = gr.Dropdown(choices=subjects, label="Choose Subject")
|
| 36 |
chatbot = gr.Chatbot()
|
| 37 |
-
question = gr.Textbox(label="
|
| 38 |
state = gr.State([])
|
| 39 |
|
| 40 |
submit_btn = gr.Button("Get Answer")
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# ✅ Use the environment variable correctly
|
| 7 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
|
|
|
|
|
|
| 8 |
openai.api_base = "https://api.groq.com/openai/v1"
|
| 9 |
|
| 10 |
+
# Tutor chatbot function
|
| 11 |
def tutor_chatbot(subject, question, chat_history=[]):
|
| 12 |
try:
|
| 13 |
messages = [
|
|
|
|
| 16 |
]
|
| 17 |
|
| 18 |
response = openai.ChatCompletion.create(
|
| 19 |
+
model="llama3-8b-8192", # Or "gemma-7b-it"
|
| 20 |
messages=messages,
|
| 21 |
temperature=0.5,
|
| 22 |
max_tokens=800,
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return chat_history + [("Error", str(e))]
|
| 29 |
|
| 30 |
+
# List of available subjects
|
| 31 |
subjects = ["Math", "Physics", "Biology", "CSS Exam", "Computer Science", "History"]
|
| 32 |
|
| 33 |
+
# Gradio UI
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
gr.Markdown("## 📚 AI Educational Tutor Chatbot (Groq API)")
|
| 36 |
+
|
| 37 |
subject = gr.Dropdown(choices=subjects, label="Choose Subject")
|
| 38 |
chatbot = gr.Chatbot()
|
| 39 |
+
question = gr.Textbox(label="Ask your question:")
|
| 40 |
state = gr.State([])
|
| 41 |
|
| 42 |
submit_btn = gr.Button("Get Answer")
|