sankett commited on
Commit
b314b52
Β·
verified Β·
1 Parent(s): 82317e3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -0
app.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_ollama import ChatOllama
3
+ from langchain_core.output_parsers import StrOutputParser
4
+
5
+ from langchain_core.prompts import (
6
+ SystemMessagePromptTemplate,
7
+ HumanMessagePromptTemplate,
8
+ AIMessagePromptTemplate,
9
+ ChatPromptTemplate
10
+ )
11
+ # Custom CSS styling
12
+ st.markdown("""
13
+ <style>
14
+ /* Existing styles */
15
+ .main {
16
+ background-color: #1a1a1a;
17
+ color: #ffffff;
18
+ }
19
+ .sidebar .sidebar-content {
20
+ background-color: #2d2d2d;
21
+ }
22
+ .stTextInput textarea {
23
+ color: #ffffff !important;
24
+ }
25
+
26
+ /* Add these new styles for select box */
27
+ .stSelectbox div[data-baseweb="select"] {
28
+ color: white !important;
29
+ background-color: #3d3d3d !important;
30
+ }
31
+
32
+ .stSelectbox svg {
33
+ fill: white !important;
34
+ }
35
+
36
+ .stSelectbox option {
37
+ background-color: #2d2d2d !important;
38
+ color: white !important;
39
+ }
40
+
41
+ /* For dropdown menu items */
42
+ div[role="listbox"] div {
43
+ background-color: #2d2d2d !important;
44
+ color: white !important;
45
+ }
46
+ </style>
47
+ """, unsafe_allow_html=True)
48
+ st.title("🧠 DeepSeek Code Companion")
49
+ st.caption("πŸš€ Your AI Pair Programmer with Debugging Superpowers")
50
+
51
+ # Sidebar configuration
52
+ with st.sidebar:
53
+ st.header("βš™οΈ Configuration")
54
+ selected_model = st.selectbox(
55
+ "Choose Model",
56
+ ["deepseek-r1:1.5b", "deepseek-r1:3b"],
57
+ index=0
58
+ )
59
+ st.divider()
60
+ st.markdown("### Model Capabilities")
61
+ st.markdown("""
62
+ - 🐍 Python Expert
63
+ - 🐞 Debugging Assistant
64
+ - πŸ“ Code Documentation
65
+ - πŸ’‘ Solution Design
66
+ """)
67
+ st.divider()
68
+ st.markdown("Built with [Ollama](https://ollama.ai/) | [LangChain](https://python.langchain.com/)")
69
+
70
+
71
+ # initiate the chat engine
72
+
73
+ llm_engine=ChatOllama(
74
+ model=selected_model,
75
+ base_url="http://localhost:11434",
76
+
77
+ temperature=0.3
78
+
79
+ )
80
+
81
+ # System prompt configuration
82
+ system_prompt = SystemMessagePromptTemplate.from_template(
83
+ "You are an expert AI coding assistant. Provide concise, correct solutions "
84
+ "with strategic print statements for debugging. Always respond in English."
85
+ )
86
+
87
+ # Session state management
88
+ if "message_log" not in st.session_state:
89
+ st.session_state.message_log = [{"role": "ai", "content": "Hi! I'm DeepSeek. How can I help you code today? πŸ’»"}]
90
+
91
+ # Chat container
92
+ chat_container = st.container()
93
+
94
+ # Display chat messages
95
+ with chat_container:
96
+ for message in st.session_state.message_log:
97
+ with st.chat_message(message["role"]):
98
+ st.markdown(message["content"])
99
+
100
+ # Chat input and processing
101
+ user_query = st.chat_input("Type your coding question here...")
102
+
103
+ def generate_ai_response(prompt_chain):
104
+ processing_pipeline=prompt_chain | llm_engine | StrOutputParser()
105
+ return processing_pipeline.invoke({})
106
+
107
+ def build_prompt_chain():
108
+ prompt_sequence = [system_prompt]
109
+ for msg in st.session_state.message_log:
110
+ if msg["role"] == "user":
111
+ prompt_sequence.append(HumanMessagePromptTemplate.from_template(msg["content"]))
112
+ elif msg["role"] == "ai":
113
+ prompt_sequence.append(AIMessagePromptTemplate.from_template(msg["content"]))
114
+ return ChatPromptTemplate.from_messages(prompt_sequence)
115
+
116
+ if user_query:
117
+ # Add user message to log
118
+ st.session_state.message_log.append({"role": "user", "content": user_query})
119
+
120
+ # Generate AI response
121
+ with st.spinner("🧠 Processing..."):
122
+ prompt_chain = build_prompt_chain()
123
+ ai_response = generate_ai_response(prompt_chain)
124
+
125
+ # Add AI response to log
126
+ st.session_state.message_log.append({"role": "ai", "content": ai_response})
127
+
128
+ # Rerun to update chat display
129
+ st.rerun()