manutej commited on
Commit
38a85c5
·
1 Parent(s): 4a12b68

Added generate_poem

Browse files
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -6,13 +6,43 @@ import streamlit as st
6
  #logging.set_verbosity_error()
7
 
8
  #API KEYS
 
 
9
  url = st.text_area('enter a url to process')
10
  def img2text(url):
11
  image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
12
  text = image_to_text(url)[0]["generated_text"]
13
  return text
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  if url:
16
- st.write(img2text(url))
 
 
 
17
 
18
 
 
6
  #logging.set_verbosity_error()
7
 
8
  #API KEYS
9
+ openai_api_key = st.secrets['OPENAI_API_KEY']
10
+
11
  url = st.text_area('enter a url to process')
12
  def img2text(url):
13
  image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
14
  text = image_to_text(url)[0]["generated_text"]
15
  return text
16
 
17
+ def generate_poem(scenario, openai_api_key):
18
+
19
+ template = """
20
+ You are a writer and your favorite poet is Emily Dickinson.
21
+ You can generate a short poem based on a simple phrase or sentence.
22
+
23
+ CONTEXT: {scenario}
24
+ POEM:
25
+ """
26
+ prompt = PromptTemplate(template = template, input_variables = ['scenario'])
27
+
28
+ # Call LLM Chain with OpenAI's API in LangChain
29
+
30
+ poem_LLM = LLMChain(llm = ChatOpenAI(
31
+ openai_api_key = openai_api_key,
32
+ model_name = "gpt-3.5-turbo",
33
+ temperature = 0.9,
34
+ prompt = prompt,
35
+ verbose = True
36
+ ))
37
+
38
+ poem = poem_LLM.predict(scenario = scenario)
39
+ print(poem)
40
+ return poem
41
+
42
  if url:
43
+
44
+ scenario = img2text(url)
45
+ poem_output = generate_poem(scenario, openai_api_key)
46
+ st.write(poem_output)
47
 
48