Grey01 commited on
Commit
12165fa
·
verified ·
1 Parent(s): 1a1ac25

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # configuring streamlit page settings
5
+ st.set_page_config(
6
+ page_title='Digital Ink',
7
+ layout = 'centered'
8
+ )
9
+
10
+ generation_args = {
11
+ "max_new_tokens": 1000,
12
+ "return_full_text": False,
13
+ "num_beams": 5,
14
+ "do_sample": True,
15
+ "top_k": 60,
16
+ }
17
+
18
+ # Initialize the model pipeline
19
+ chat_pipeline = pipeline("text-generation", model="microsoft/Phi-3-mini-128k-instruct")
20
+
21
+ # Define system content
22
+ SYSTEM_CONTENT = "You are a helpful assistant named Digital Ink. Your purpose is to provide creative engaging and effective marketing content.You can introduce your self as follows: I'm Digital Ink, a marketing content generation model. I'm designed to assist you in creating engaging and effective marketing content, such as blog posts, social media posts, and product descriptions"
23
+
24
+ # Streamlit app
25
+ st.title("Digital Ink")
26
+
27
+ # Initialize the chat history
28
+ if 'messages' not in st.session_state:
29
+ st.session_state.messages = [{"role": "system", "content": SYSTEM_CONTENT}]
30
+
31
+
32
+
33
+ # User input
34
+ user_input = st.chat_input("Ask Digital Ink..")
35
+
36
+ if user_input:
37
+ # Add user message to chat history
38
+ st.session_state.messages.append({"role": "user", "content": user_input})
39
+
40
+ # Generate response from chatbot
41
+ context = [msg['content'] for msg in st.session_state.messages]
42
+ response = chat_pipeline(context, **generation_args)[0]['generated_text']
43
+
44
+ # Add assistant response to chat history
45
+ st.session_state.messages.append({"role": "assistant", "content": response})
46
+
47
+ # Redisplay chat history
48
+ st.experimental_rerun()