johnnygreco commited on
Commit
2466361
β€’
1 Parent(s): f0774cf
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- title: The Gpt Who Lived
3
- emoji: 😻
4
  colorFrom: purple
5
  colorTo: purple
6
  sdk: gradio
1
  ---
2
+ title: πŸ§™β€β™‚οΈ The GPT Who Lived πŸ€–
3
+ emoji: πŸͺ„
4
  colorFrom: purple
5
  colorTo: purple
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+
4
+ import gradio as gr
5
+ import hpqa
6
+ from langchain import VectorDBQA
7
+ from langchain.llms import OpenAI
8
+
9
+ os.environ["OPENAI_API_KEY"] = ""
10
+ index_path = Path("data/hpqa_faiss_index_500")
11
+
12
+
13
+ examples = [
14
+ "How would you sneak into Hogwarts without being detected?",
15
+ "Why did Snape kill Dumbledore?",
16
+ "Who is the most badass wizard in the world?",
17
+ "Who would win a fight between Dumbledore and a grizzly bear?",
18
+ "How many siblings does Hermione have?",
19
+ "Why are the Dursleys so mean to Harry?",
20
+ ]
21
+
22
+
23
+ def api(question, temperature, api_key=None):
24
+ if api_key is None or len(api_key) == 0:
25
+ return "You must provide an OpenAI API key to use this demo πŸ‘‡"
26
+ if len(question) == 0:
27
+ return ""
28
+ document_store = hpqa.load_document_store(index_path, openai_api_key=api_key)
29
+ chain = VectorDBQA.from_chain_type(
30
+ llm=OpenAI(temperature=temperature, openai_api_key=api_key),
31
+ chain_type="stuff",
32
+ vectorstore=document_store,
33
+ return_source_documents=True,
34
+ )
35
+ response = chain(question)
36
+ return response["result"].strip()
37
+
38
+
39
+ demo = gr.Blocks()
40
+
41
+ with demo:
42
+ gr.Markdown("# πŸͺ„ Harry Potter Question-Answering with GPT πŸ€–")
43
+ with gr.Row():
44
+ with gr.Column():
45
+ question = gr.Textbox(lines=4, label="Question")
46
+ temperature = gr.Slider(0.0, 2.0, 0.7, step=0.1, label="🍺 Butterbeer Consumed")
47
+ with gr.Row():
48
+ clear = gr.Button("Clear")
49
+ btn = gr.Button("Submit", variant="primary")
50
+ with gr.Column():
51
+ answer = gr.Textbox(lines=4, label="Answer")
52
+ openai_api_key = gr.Textbox(type="password", label="OpenAI API key")
53
+ btn.click(api, [question, temperature, openai_api_key], answer)
54
+ clear.click(lambda _: "", question, question)
55
+ gr.Examples(examples, question)
56
+ demo.launch()
data/hpqa_faiss_index_500/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fc48f66967f6bf7474dc98242ff4ac8660d88d397140f47912c54b2df2a4862d
3
+ size 20195373
data/hpqa_faiss_index_500/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc6dcdacdf6a35b8a71e6b779cde261339c073830048e784935fe4b88b6b0ca8
3
+ size 7093398
requirements.txt ADDED
@@ -0,0 +1 @@
 
1
+ git+https://github.com/johnnygreco/hpqa.git