Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
apikey.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
apikey= ''
|
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Bring in deps
|
| 2 |
+
import os
|
| 3 |
+
from apikey import apikey
|
| 4 |
+
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from langchain.llms import OpenAI
|
| 7 |
+
from langchain.prompts import PromptTemplate
|
| 8 |
+
from langchain.chains import LLMChain
|
| 9 |
+
from langchain.memory import ConversationBufferMemory
|
| 10 |
+
from langchain.utilities import WikipediaAPIWrapper
|
| 11 |
+
|
| 12 |
+
# Set OpenAI API key
|
| 13 |
+
os.environ['OPENAI_API_KEY'] = apikey
|
| 14 |
+
|
| 15 |
+
# App framework
|
| 16 |
+
st.title('Test bot')
|
| 17 |
+
prompt = st.text_input('Plug in the topic here')
|
| 18 |
+
|
| 19 |
+
# Check if there's a prompt
|
| 20 |
+
if prompt:
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
question_template = PromptTemplate(
|
| 24 |
+
input_variables=['topic', 'wikipedia_research','answer'],
|
| 25 |
+
template='create 5 multiple-choice question and answer with the following information: QUESTION: {topic} OPTIONS: {wikipedia_research} ANSWER: {wikipedia_research}'
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# Memory
|
| 31 |
+
|
| 32 |
+
question_memory = ConversationBufferMemory(input_key='topic', memory_key='chat_history')
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Llms
|
| 36 |
+
llm = OpenAI(temperature=0.9)
|
| 37 |
+
|
| 38 |
+
question_chain = LLMChain(llm=llm, prompt=question_template, verbose=True, output_key='question', memory=question_memory)
|
| 39 |
+
|
| 40 |
+
wiki = WikipediaAPIWrapper()
|
| 41 |
+
|
| 42 |
+
# Run chains
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
wiki_research = wiki.run(prompt)
|
| 46 |
+
question = question_chain.run(topic=prompt, wikipedia_research=wiki_research)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
st.write("Question:", question)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
with st.expander('Question history'):
|
| 57 |
+
st.info(question_memory.buffer)
|
| 58 |
+
|
| 59 |
+
with st.expander('Wikipedia Research'):
|
| 60 |
+
st.info(wiki_research)
|
| 61 |
+
else:
|
| 62 |
+
st.warning("Please enter your topic.")
|