dincertolga commited on
Commit
a840cf1
·
verified ·
1 Parent(s): ac8d453

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain.llms import OpenAI
4
+ import os
5
+
6
+ def get_llm_response(input_text, num_words, blog_style):
7
+
8
+ # calling llama model
9
+ llm = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"), temperature = 0.5)
10
+ # prompt template
11
+
12
+ template = """ Write a blog for {blog_style} job profie for the topic {input_text} within {num_words} words. """
13
+
14
+ prompt = PromptTemplate(input_variables =["blog_style","input_text","num_words"],
15
+ template = template)
16
+
17
+ # generate response from openai
18
+ response = llm(prompt.format(blog_style = blog_style,input_text=input_text, num_words= num_words))
19
+
20
+ print(response)
21
+ return response
22
+
23
+
24
+ st.set_page_config(page_title = "Generate a Blog",
25
+ layout = "centered",
26
+ initial_sidebar_state = "collapsed")
27
+
28
+ st.header('Generate Blogs')
29
+
30
+ input_text = st.text_input("Enter the blog topic")
31
+
32
+ # create two more columns for additional fields
33
+ col1,col2 = st.columns([5,5])
34
+
35
+ with col1:
36
+ num_words= st.text_input("Number of Words")
37
+ with col2:
38
+ blog_style = st.selectbox('Writing the blog for',
39
+ ('Researchers', 'Data Scientists', 'Common People'), index = 0)
40
+ submit = st.button("Generate")
41
+
42
+ # final response
43
+
44
+ if submit:
45
+ st.write(get_llm_response(input_text, num_words, blog_style))
46
+
47
+