Spaces:
Sleeping
Sleeping
ruchi
commited on
Commit
·
da5916b
1
Parent(s):
1acaba1
First commit
Browse files- app.py +39 -0
- dump.txt +37 -0
- htmlTemplates.py +85 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-chat-hf")
|
9 |
+
|
10 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_length=200))
|
11 |
+
|
12 |
+
|
13 |
+
# Create a banner using Markdown
|
14 |
+
st.markdown(
|
15 |
+
"""
|
16 |
+
<div style="min-width: 1000px;">
|
17 |
+
<div style="background-color:#f63366;padding:10px;border-radius:10px;">
|
18 |
+
<h1 style="color:white;text-align:center;">Red Octopus</h1>
|
19 |
+
</div>
|
20 |
+
<div style="color:black;text-align:center;">
|
21 |
+
<h1>Welcome to the Proposition Management Tool</h1>
|
22 |
+
</div>
|
23 |
+
</div>
|
24 |
+
""",
|
25 |
+
unsafe_allow_html=True
|
26 |
+
)
|
27 |
+
|
28 |
+
selectedCity = st.selectbox("Please select the City and the Bank Product for Your Proposition.", ["CharlesTown", "Limburg"])
|
29 |
+
selectedProduct = st.selectbox("Please select the Product", ["Current", "Mortage", "Credit Card", "Crypto"])
|
30 |
+
userProposal = st.text_input("Enter your Proposition for Select City and Product")
|
31 |
+
|
32 |
+
submit_button = st.button("Submit")
|
33 |
+
|
34 |
+
if submit_button:
|
35 |
+
st.write("You clicked the Submit button!")
|
36 |
+
st.write("Entered text:", userProposal)
|
37 |
+
result = pipe(f"<s>[INST] {userProposal} [/INST]")
|
38 |
+
st.write(result)
|
39 |
+
|
dump.txt
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Initialize chat history
|
2 |
+
if "messages" not in st.session_state:
|
3 |
+
st.session_state.messages = []
|
4 |
+
|
5 |
+
# Display chat messages from history on app rerun
|
6 |
+
for message in st.session_state.messages:
|
7 |
+
with st.chat_message(message["role"]):
|
8 |
+
st.markdown(message["content"])
|
9 |
+
|
10 |
+
# Accept user input
|
11 |
+
if prompt := st.chat_input("What is up?"):
|
12 |
+
# Add user message to chat history
|
13 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
14 |
+
# Display user message in chat message container
|
15 |
+
with st.chat_message("user"):
|
16 |
+
st.markdown(prompt)
|
17 |
+
|
18 |
+
# Display assistant response in chat message container
|
19 |
+
with st.chat_message("assistant"):
|
20 |
+
message_placeholder = st.empty()
|
21 |
+
full_response = ""
|
22 |
+
assistant_response = random.choice(
|
23 |
+
[
|
24 |
+
"Hello there! How can I assist you today?",
|
25 |
+
"Hi, human! Is there anything I can help you with?",
|
26 |
+
"Do you need help?",
|
27 |
+
]
|
28 |
+
)
|
29 |
+
# Simulate stream of response with milliseconds delay
|
30 |
+
for chunk in assistant_response.split():
|
31 |
+
full_response += chunk + " "
|
32 |
+
time.sleep(0.05)
|
33 |
+
# Add a blinking cursor to simulate typing
|
34 |
+
message_placeholder.markdown(full_response + "▌")
|
35 |
+
message_placeholder.markdown(full_response)
|
36 |
+
# Add assistant response to chat history
|
37 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
htmlTemplates.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
css="""<style>
|
2 |
+
body {
|
3 |
+
font-family: 'Arial', sans-serif;
|
4 |
+
background-color: #f0f0f0;
|
5 |
+
margin: 0;
|
6 |
+
padding: 0;
|
7 |
+
}
|
8 |
+
|
9 |
+
#banner {
|
10 |
+
background-color: #ff4500;
|
11 |
+
color: white;
|
12 |
+
padding: 10px;
|
13 |
+
text-align: center;
|
14 |
+
font-size: 24px;
|
15 |
+
}
|
16 |
+
|
17 |
+
#form-container {
|
18 |
+
margin: 50px auto;
|
19 |
+
padding: 20px;
|
20 |
+
background-color: #ffffff;
|
21 |
+
border-radius: 8px;
|
22 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
23 |
+
}
|
24 |
+
|
25 |
+
input[type="text"] {
|
26 |
+
width: 100%;
|
27 |
+
padding: 10px;
|
28 |
+
margin-bottom: 10px;
|
29 |
+
border: 1px solid #ccc;
|
30 |
+
border-radius: 4px;
|
31 |
+
box-sizing: border-box;
|
32 |
+
}
|
33 |
+
|
34 |
+
button {
|
35 |
+
background-color: #4caf50;
|
36 |
+
color: white;
|
37 |
+
padding: 10px 15px;
|
38 |
+
border: none;
|
39 |
+
border-radius: 4px;
|
40 |
+
cursor: pointer;
|
41 |
+
font-size: 16px;
|
42 |
+
}
|
43 |
+
|
44 |
+
#output {
|
45 |
+
margin-top: 20px;
|
46 |
+
padding: 10px;
|
47 |
+
background-color: #f8f8f8;
|
48 |
+
border: 1px solid #ddd;
|
49 |
+
border-radius: 4px;
|
50 |
+
}
|
51 |
+
</style>
|
52 |
+
"""
|
53 |
+
bot_template = """
|
54 |
+
<div id="banner">
|
55 |
+
Red Octopus
|
56 |
+
</div>
|
57 |
+
|
58 |
+
<div id="form-container">
|
59 |
+
<form id="input_form">
|
60 |
+
<label for="input_text">Enter your text:</label>
|
61 |
+
<input type="text" id="input_text" name="input_text" required>
|
62 |
+
<br>
|
63 |
+
<button type="button" onclick="submitForm()">Submit</button>
|
64 |
+
</form>
|
65 |
+
</div>
|
66 |
+
|
67 |
+
<div id="output"></div>
|
68 |
+
|
69 |
+
<script>
|
70 |
+
function submitForm() {
|
71 |
+
var inputText = document.getElementById('input_text').value;
|
72 |
+
fetch('/predict', {
|
73 |
+
method: 'POST',
|
74 |
+
headers: {
|
75 |
+
'Content-Type': 'application/json',
|
76 |
+
},
|
77 |
+
body: JSON.stringify({ text: inputText }),
|
78 |
+
})
|
79 |
+
.then(response => response.json())
|
80 |
+
.then(data => {
|
81 |
+
document.getElementById('output').innerText = 'Model Prediction: ' + data.prediction;
|
82 |
+
});
|
83 |
+
}
|
84 |
+
</script>
|
85 |
+
"""
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
altair==4.0
|