Subalakshmi commited on
Commit
ea6ebd7
·
verified ·
1 Parent(s): bb79f19

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +51 -0
  3. requirement.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN useradd user
10
+
11
+ USER user
12
+
13
+ ENV HOME=/home/user \
14
+ PATH=/home/user/.local/bin:$PATH
15
+
16
+ WORKDIR $HOME/app
17
+
18
+ COPY --chown=user . $HOME/app
19
+
20
+ CMD [ "uvicorn","app:app","--host","0.0.0.0","--port","7860" ]
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.llms import CTransformers
4
+
5
+ def getLLamaresponse(input_text, no_words, blog_style):
6
+ # Initialize the language model with the specified configuration
7
+ # Use a pipeline as a high-level helper
8
+ from transformers import pipeline
9
+ llm = pipeline("text-generation", model="TheBloke/Llama-2-7B-Chat-GGML")
10
+ # Define the template for the prompt
11
+ template = """
12
+ Write a blog in {blog_style} job profile for the topic "{input_text}" within {no_words} words.
13
+ """
14
+
15
+ # Create the prompt using the template
16
+ prompt = PromptTemplate(input_variables=['blog_style', 'input_text', 'no_words'], template=template)
17
+
18
+ # Format the prompt with the provided parameters
19
+ formatted_prompt = prompt.format(blog_style=blog_style, input_text=input_text, no_words=no_words)
20
+
21
+ # Generate the response using the language model
22
+ response = llm(formatted_prompt)
23
+
24
+ return response
25
+
26
+ # Configure the Streamlit app
27
+ st.set_page_config(page_title="Generate Blog",
28
+ layout='centered',
29
+ initial_sidebar_state='collapsed')
30
+
31
+ # App header
32
+ st.header("Generate Blog")
33
+
34
+ # Input for the blog topic
35
+ input_text = st.text_input("Enter the blog topic")
36
+
37
+ # Columns for additional inputs
38
+ col1, col2 = st.columns([5, 5])
39
+ with col1:
40
+ no_words = st.text_input('Number of words')
41
+
42
+ with col2:
43
+ blog_style = st.selectbox('Writing the blog for', ('researchers', 'data scientists', 'common people'), index=0)
44
+
45
+ # Generate button
46
+ submit = st.button("Generate")
47
+
48
+ # Display the generated response
49
+ if submit:
50
+ response = getLLamaresponse(input_text, no_words, blog_style)
51
+ st.write(response)
requirement.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ sentence-transformers
2
+ uvicorn
3
+ langchain
4
+ python-box
5
+ streamlit