AhmedUddin2002 commited on
Commit
54a011e
Β·
verified Β·
1 Parent(s): fd924e5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +57 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,58 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from langchain.chat_models import ChatOpenAI
3
+ from langchain.memory import ConversationBufferMemory
4
+ from langchain.chains import ConversationChain
5
+ import os
6
+
7
+ # Set your OpenAI API Key
8
+ os.environ["OPENAI_API_KEY"] = "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"
9
+
10
+ # 🌐 OpenRouter base URL
11
+ OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1"
12
+
13
+ # πŸ€– Choose model (you can change this)
14
+ MODEL_NAME = "openai/gpt-oss-120b:free"
15
+
16
+ # Initialize LLM
17
+ llm = ChatOpenAI(
18
+ model=MODEL_NAME,
19
+ temperature=0.7,
20
+ base_url=OPENROUTER_BASE_URL
21
+ )
22
+
23
+
24
+ # Memory (stores conversation)
25
+ memory = ConversationBufferMemory()
26
+
27
+ # Conversation chain
28
+ conversation = ConversationChain(
29
+ llm=llm,
30
+ memory=memory,
31
+ verbose=True
32
+ )
33
+
34
+ # Streamlit UI
35
+ st.set_page_config(page_title="Simple Chatbot", page_icon="πŸ€–")
36
+ st.title("πŸ€– Simple LangChain Chatbot")
37
+
38
+ # Session state for chat history
39
+ if "chat_history" not in st.session_state:
40
+ st.session_state.chat_history = []
41
+
42
+ # User input
43
+ user_input = st.text_input("You:", placeholder="Ask something...")
44
+
45
+ if user_input:
46
+ # Get response from LangChain
47
+ response = conversation.predict(input=user_input)
48
+
49
+ # Store chat
50
+ st.session_state.chat_history.append(("You", user_input))
51
+ st.session_state.chat_history.append(("Bot", response))
52
+
53
+ # Display chat history
54
+ for role, text in st.session_state.chat_history:
55
+ if role == "You":
56
+ st.markdown(f"**πŸ§‘ You:** {text}")
57
+ else:
58
+ st.markdown(f"**πŸ€– Bot:** {text}")