Tesla_ChatBot / app.py
Gowthamvemula's picture
Update app.py
acdc1e9 verified
# tesla_chatbot.py
import streamlit as st
import openai
# Set your OpenAI API key
openai.api_key = "YOUR_OPENAI_API_KEY" # Replace with your API key
# Tesla knowledge base prompt
BASE_PROMPT = """
You are a helpful Tesla assistant.
You can answer questions about Tesla cars (Model S, 3, X, Y), technology (Autopilot, Full Self Driving), Tesla Energy products (Solar Roof, Powerwall), service, and company information.
If you don't know the answer or it's not Tesla-related, say "I'm sorry, I can only assist with Tesla-related queries."
Answer concisely and clearly.
"""
# Streamlit UI
st.set_page_config(page_title="Tesla Chatbot πŸš—βš‘", page_icon="πŸš—")
st.title("πŸš— Tesla Chatbot")
st.write("Ask me anything about Tesla cars, products, and services!")
user_input = st.text_input("You:", "")
if st.button("Ask"):
if user_input.strip() == "":
st.warning("Please type a question.")
else:
with st.spinner("Thinking..."):
# Call OpenAI to get the response
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # You can use gpt-4 if you have access
messages=[
{"role": "system", "content": BASE_PROMPT},
{"role": "user", "content": user_input}
],
temperature=0.5,
max_tokens=300,
)
reply = response['choices'][0]['message']['content']
st.success(reply)