darthPanda commited on
Commit
95b4a29
·
1 Parent(s): af31b9c

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -81
app.py DELETED
@@ -1,81 +0,0 @@
1
- import streamlit as st
2
- from streamlit_chat import message
3
- import requests
4
- from gpt_index import SimpleDirectoryReader,GPTListIndex,GPTSimpleVectorIndex,LLMPredictor,PromptHelper,ServiceContext
5
- from langchain import OpenAI
6
- import sys
7
- import os
8
-
9
- st.set_page_config(
10
- page_title="Chatbot",
11
- page_icon=":robot_face:"
12
- )
13
-
14
- def api_key_callback():
15
- # api_key = st.session_state.api_key_input
16
- os.environ["OPENAI_API_KEY"] = st.session_state.api_key_input
17
- # print(st.session_state.api_key_input)
18
-
19
- def api_form():
20
- with st.form(key="search_form"):
21
- st.subheader("API Key")
22
- st.text_input("Enter your OpenAI API key", key="api_key_input")
23
- st.form_submit_button(label="Submit", on_click=api_key_callback)
24
- st.caption('''
25
- This api key wil not be stored and deleted at the end of your web session.
26
- For more details, you can check out the
27
- [Source Code](https://huggingface.co/spaces/darthPanda/romeo_and_juliet_chatbot_with_gptIndex/tree/main).
28
- If you want to be extra careful, you can delete your
29
- [OpenAI API key](https://platform.openai.com/account/api-keys)
30
- after using this space.
31
- ''')
32
-
33
- with st.sidebar:
34
- st.title("Romeo and Juliet Chatbot")
35
- st.markdown('''
36
- <div>
37
- This gpt3 based chatbot has been
38
- trained on famous play <b>Romeo and Juliet</b> by William Shakespeare
39
- </div>
40
- ''', unsafe_allow_html=True)
41
- api_form()
42
- # st.markdown("[Source Code](https://github.com/ai-yash/st-chat)")
43
- # st.markdown("[Book Link](https://www.gutenberg.org/ebooks/1513)")
44
- st.markdown(
45
- "<div style='position: fixed; bottom: 0;'>Created by Taaha Bajwa</div>",
46
- unsafe_allow_html=True,
47
- )
48
-
49
- st.markdown('Ask me any question from Romeo and Juliet')
50
-
51
- if 'generated' not in st.session_state:
52
- st.session_state['generated'] = []
53
-
54
- if 'past' not in st.session_state:
55
- st.session_state['past'] = []
56
-
57
- def query(payload):
58
- vIndex = GPTSimpleVectorIndex.load_from_disk('vectorIndex.json')
59
- response = vIndex.query(payload,response_mode='compact')
60
- # print(str(response))
61
- return (str(response)).lstrip()
62
-
63
- def get_text():
64
- input_text = st.text_input("You: ","", key="input")
65
- return input_text
66
-
67
-
68
- user_input = get_text()
69
-
70
- if user_input:
71
- try:
72
- output = query(user_input)
73
- st.session_state.past.append(user_input)
74
- st.session_state.generated.append(output)
75
- except:
76
- st.error('Invalid API key', icon="🚨")
77
-
78
- if st.session_state['generated']:
79
- for i in range(len(st.session_state['generated'])-1, -1, -1):
80
- message(st.session_state["generated"][i], key=str(i))
81
- message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')