Manoj21k commited on
Commit
9531b5f
·
verified ·
1 Parent(s): 7188009

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from langchain.memory.chat_message_histories import StreamlitChatMessageHistory
4
+ import time
5
+ from main import get_prompt
6
+
7
+ # Sidebar for selecting the model and entering the API key
8
+ st.sidebar.title("API Configuration")
9
+ api = st.sidebar.text_input("Enter your Anthropic API key", type="password")
10
+ st.sidebar.markdown("Get the API key from here: [https://console.anthropic.com/settings/keys](https://console.anthropic.com/settings/keys)")
11
+ icons = ""
12
+ # Chat interface
13
+ st.title("Prompt Writer")
14
+
15
+ # Store LLM-generated responses
16
+ if "messages" not in st.session_state.keys():
17
+ st.session_state.messages = [{"role": "assistant", "content": "Hi. I'm an LLM powered prompting assistant helping you with writing efficient prompts to LLM for specific task. Give me the task as input."}]
18
+
19
+ for message in st.session_state.messages:
20
+ with st.chat_message(message["role"]):
21
+ st.write(message["content"])
22
+
23
+ msgs = StreamlitChatMessageHistory(key="special_app_key")
24
+
25
+ for msg in msgs.messages:
26
+ st.chat_message(msg.type).write(msg.content)
27
+
28
+ if prompt := st.chat_input():
29
+ start_time = time.time()
30
+ st.chat_message("human").write(prompt)
31
+ msgs.add_user_message(prompt)
32
+
33
+ with st.spinner("Waiting for response..."):
34
+ res = get_prompt(prompt, api)
35
+ if res:
36
+ st.chat_message("ai").write(res)
37
+ end_time = time.time()
38
+ msgs.add_ai_message(res)
39
+ else:
40
+ st.error("No valid response received from the AI.")