Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import markdown
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Custom CSS with animations and dark theme
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
background-color: #1a1a1a;
|
| 12 |
+
color: #ffffff;
|
| 13 |
+
}
|
| 14 |
+
.stApp {
|
| 15 |
+
background-color: #1a1a1a;
|
| 16 |
+
}
|
| 17 |
+
.chat-container {
|
| 18 |
+
background-color: #2c2c2c;
|
| 19 |
+
border-radius: 10px;
|
| 20 |
+
padding: 20px;
|
| 21 |
+
margin-top: 20px;
|
| 22 |
+
transition: all 0.3s ease;
|
| 23 |
+
}
|
| 24 |
+
.chat-container:hover {
|
| 25 |
+
box-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
|
| 26 |
+
}
|
| 27 |
+
.stTextInput > div > input {
|
| 28 |
+
background-color: #3a3a3a;
|
| 29 |
+
color: #ffffff;
|
| 30 |
+
border: 1px solid #00ffff;
|
| 31 |
+
border-radius: 5px;
|
| 32 |
+
transition: border-color 0.3s ease;
|
| 33 |
+
}
|
| 34 |
+
.stTextInput > div > input:focus {
|
| 35 |
+
border-color: #ff00ff;
|
| 36 |
+
}
|
| 37 |
+
.stButton > button {
|
| 38 |
+
background-color: #00ffff;
|
| 39 |
+
color: #000000;
|
| 40 |
+
border-radius: 5px;
|
| 41 |
+
transition: background-color 0.3s ease;
|
| 42 |
+
}
|
| 43 |
+
.stButton > button:hover {
|
| 44 |
+
background-color: #ff00ff;
|
| 45 |
+
}
|
| 46 |
+
.message {
|
| 47 |
+
background-color: #3a3a3a;
|
| 48 |
+
border-radius: 10px;
|
| 49 |
+
padding: 10px;
|
| 50 |
+
margin: 10px 0;
|
| 51 |
+
animation: fadeIn 0.5s ease-in;
|
| 52 |
+
}
|
| 53 |
+
@keyframes fadeIn {
|
| 54 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 55 |
+
to { opacity: 1; transform: translateY(0); }
|
| 56 |
+
}
|
| 57 |
+
</style>
|
| 58 |
+
""", unsafe_allow_html=True)
|
| 59 |
+
|
| 60 |
+
# Initialize session state for chat history
|
| 61 |
+
if "messages" not in st.session_state:
|
| 62 |
+
st.session_state.messages = []
|
| 63 |
+
|
| 64 |
+
# Title and header
|
| 65 |
+
st.title("Tesla Manufacturing AI Chatbot")
|
| 66 |
+
st.markdown("Explore Tesla's AI use cases and ask questions about manufacturing innovations.")
|
| 67 |
+
|
| 68 |
+
# Display report
|
| 69 |
+
st.header("AI Use Case Report")
|
| 70 |
+
try:
|
| 71 |
+
with open("tesla_ai_use_cases/tesla_ai_use_case_report.md", "r") as f:
|
| 72 |
+
report_content = f.read()
|
| 73 |
+
st.markdown(report_content)
|
| 74 |
+
except FileNotFoundError:
|
| 75 |
+
st.error("Report file not found. Please run the main script first.")
|
| 76 |
+
|
| 77 |
+
# Chat interface
|
| 78 |
+
st.header("Chat with the AI")
|
| 79 |
+
with st.container():
|
| 80 |
+
st.markdown('<div class="chat-container">', unsafe_allow_html=True)
|
| 81 |
+
|
| 82 |
+
# Display chat history
|
| 83 |
+
for message in st.session_state.messages:
|
| 84 |
+
with st.container():
|
| 85 |
+
st.markdown(f'<div class="message">{message["role"]}: {message["content"]}</div>', unsafe_allow_html=True)
|
| 86 |
+
|
| 87 |
+
# Input form
|
| 88 |
+
with st.form(key="chat_form", clear_on_submit=True):
|
| 89 |
+
prompt = st.text_input("Ask about Tesla's manufacturing (e.g., 'Explain Gigapress')", key="prompt")
|
| 90 |
+
submit_button = st.form_submit_button("Send")
|
| 91 |
+
|
| 92 |
+
if submit_button and prompt:
|
| 93 |
+
# Add user message
|
| 94 |
+
st.session_state.messages.append({"role": "User", "content": prompt})
|
| 95 |
+
|
| 96 |
+
# Generate response (placeholder until LLM is fine-tuned)
|
| 97 |
+
try:
|
| 98 |
+
generator = pipeline("text-generation", model="tesla_ai_use_cases/fine_tuned_tesla_llm")
|
| 99 |
+
response = generator(prompt, max_length=200, num_return_sequences=1)[0]["generated_text"]
|
| 100 |
+
except Exception as e:
|
| 101 |
+
response = f"LLM not yet fine-tuned. Placeholder response: Ask about Gigapress, 4680 cells, or AI use cases. Error: {str(e)}"
|
| 102 |
+
|
| 103 |
+
# Add AI response
|
| 104 |
+
st.session_state.messages.append({"role": "AI", "content": response})
|
| 105 |
+
|
| 106 |
+
# Rerun to update chat
|
| 107 |
+
st.rerun()
|
| 108 |
+
|
| 109 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 110 |
+
|
| 111 |
+
# Sidebar with info
|
| 112 |
+
st.sidebar.header("About")
|
| 113 |
+
st.sidebar.markdown("""
|
| 114 |
+
This chatbot uses a fine-tuned LLM to answer questions about Tesla's manufacturing processes, such as Gigapress, 4680 cells, and AI-driven factory optimization. The data is sourced from Tesla's website, Wikipedia, and industry reports.
|
| 115 |
+
""")
|
| 116 |
+
```
|