Sanket-Kakad commited on
Commit
bf8ef1c
β€’
1 Parent(s): a86717d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import google.generativeai as genai
2
+ import streamlit as st
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+
7
+ @st.cache_resource
8
+ def get_llm():
9
+ load_dotenv()
10
+ api_key = os.environ.get('API_KEY')
11
+ genai.configure(api_key=api_key)
12
+ model = genai.GenerativeModel(
13
+ 'gemini-pro', generation_config={"temperature": temperature})
14
+ return model
15
+
16
+
17
+ st.title("Medium.com Blog Generator πŸ§‘πŸ»β€πŸ’»!!!")
18
+
19
+
20
+ def get_genai_response(prompt, question):
21
+ response = model.generate_content([prompt, question])
22
+ # print(response.text)
23
+ return response.text
24
+
25
+
26
+ prompt = """
27
+ Imagine you're a friendly expert at a local library. Tailor your explanation to a general audience who might have some curiosity about the topic but no prior in-depth knowledge. Make the information engaging and informative, and keep in mind the best practices for writing on Medium.com"""
28
+
29
+
30
+ topic = st.text_input("Topic")
31
+
32
+ creativity_arr = ["High Accuracy",
33
+ "Balanced Accuracy & Creativity", "High Creativity "]
34
+ creativity = st.selectbox("Choose creativity level:", creativity_arr)
35
+
36
+ if creativity == "High Accuracy":
37
+ temperature = 0.1
38
+ elif creativity == "Balanced Accuracy & Creativity":
39
+ temperature = 0.5
40
+ else:
41
+ temperature = 0.8
42
+
43
+ submit_button = st.button("Submit")
44
+
45
+ model = get_llm()
46
+
47
+ if submit_button:
48
+ st.header("Response")
49
+ with st.spinner(text="Fetching response from LLM..."):
50
+ text = get_genai_response(
51
+ prompt, topic)
52
+ st.write(text)