arnavagrawal commited on
Commit
531d778
·
1 Parent(s): 4e99bdb

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +6 -5
  2. app.py +31 -0
  3. guide1.txt +0 -0
  4. requirements.txt +4 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
- title: QuestionMyDoc
3
- emoji: 🚀
4
- colorFrom: purple
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.41.2
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: TalkToMyDoc Hitch Hikers Guide
3
+ emoji: 🐠
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 3.27.0
8
  app_file: app.py
9
  pinned: false
10
+ license: openrail
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.embeddings.openai import OpenAIEmbeddings
2
+ from langchain.vectorstores import Chroma
3
+ from langchain.text_splitter import CharacterTextSplitter
4
+ from langchain.chains.question_answering import load_qa_chain
5
+ from langchain.llms import OpenAI
6
+ import os
7
+ import gradio as gr
8
+
9
+ with open("guide1.txt") as f:
10
+ hitchhikersguide = f.read()
11
+
12
+ text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=100, separator = "\n")
13
+ texts = text_splitter.split_text(hitchhikersguide)
14
+ embeddings = OpenAIEmbeddings()
15
+ docsearch = Chroma.from_texts(texts, embeddings, metadatas=[{"source": str(i)} for i in range(len(texts))]).as_retriever()
16
+ chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff")
17
+
18
+ def make_inference(query):
19
+ docs = docsearch.get_relevant_documents(query)
20
+ return(chain.run(input_documents=docs, question=query))
21
+
22
+ if __name__ == "__main__":
23
+ gr.Interface(
24
+ make_inference,
25
+ [
26
+ gr.inputs.Textbox(lines=2, label="Query"),
27
+ ],
28
+ gr.outputs.Textbox(label="Response"),
29
+ title="QuestionMyDoc",
30
+ description="QuestionMyDoc is a tool that allows you to ask questions about a document. In this case - Hitch Hitchhiker's Guide to the Galaxy.",
31
+ ).launch()
guide1.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ langchain
2
+ openai
3
+ tiktoken
4
+ chromadb