brianjking commited on
Commit
57025a9
1 Parent(s): dc2c84a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1,6 +1,3 @@
1
- # Author: Brian King
2
- # For: BrandMuscle, Copyright 2023 All Rights Reserved
3
-
4
  import streamlit as st
5
  import os
6
  from llama_index import (
@@ -12,7 +9,7 @@ from llama_index.llms import OpenAI
12
  import openai
13
 
14
  # Define Streamlit layout and interaction
15
- st.title("Streamlit App for PDF Retrieval and Text Generation")
16
 
17
  # Upload PDF
18
  uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
@@ -51,12 +48,12 @@ if 'retrieved_text' not in st.session_state:
51
  if st.button("Retrieve"):
52
  with st.spinner('Retrieving text...'):
53
  # Use VectorStoreIndex to search
54
- query_engine = index.as_query_engine(similarity_top_k=3)
55
  st.session_state['retrieved_text'] = query_engine.query(user_query)
56
- st.write(f"Retrieved Text: {st.session_state['retrieved_text']}")
57
 
58
  # Select content type
59
- content_type = st.selectbox("Select content type:", ["Blog", "Tweet"])
60
 
61
  # Generate text based on retrieved text and selected content type
62
  if st.button("Generate") and content_type:
@@ -65,7 +62,7 @@ if st.button("Generate") and content_type:
65
  openai.api_key = os.getenv("OPENAI_API_KEY")
66
  try:
67
  if content_type == "Blog":
68
- prompt = f"Write a blog about 500 words in length using the {st.session_state['retrieved_text']}"
69
  elif content_type == "Tweet":
70
  prompt = f"Compose a tweet using the {st.session_state['retrieved_text']}"
71
  response = openai.ChatCompletion.create(
 
 
 
 
1
  import streamlit as st
2
  import os
3
  from llama_index import (
 
9
  import openai
10
 
11
  # Define Streamlit layout and interaction
12
+ st.title("Grounded Generations")
13
 
14
  # Upload PDF
15
  uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
 
48
  if st.button("Retrieve"):
49
  with st.spinner('Retrieving text...'):
50
  # Use VectorStoreIndex to search
51
+ query_engine = index.as_query_engine(similarity_top_k=3)
52
  st.session_state['retrieved_text'] = query_engine.query(user_query)
53
+ st.write(f"Retrieved Text: {st.session_state['retrieved_text']}") # store the retrieved text as a streamlit state variable
54
 
55
  # Select content type
56
+ content_type = st.selectbox("Select content type:", ["Blog", "Tweet"]) # make some default nonsense
57
 
58
  # Generate text based on retrieved text and selected content type
59
  if st.button("Generate") and content_type:
 
62
  openai.api_key = os.getenv("OPENAI_API_KEY")
63
  try:
64
  if content_type == "Blog":
65
+ prompt = f"Write a blog about 500 words in length using the {st.session_state['retrieved_text']}" #uses content from the stored state
66
  elif content_type == "Tweet":
67
  prompt = f"Compose a tweet using the {st.session_state['retrieved_text']}"
68
  response = openai.ChatCompletion.create(