Spaces:
Runtime error
Runtime error
JuliaUpton
commited on
Commit
•
11bc1a1
1
Parent(s):
ef10368
Upload 4 files
Browse files- README.md +6 -6
- app.py +36 -0
- guide1.txt +0 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
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,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
8 |
+
with open("guide1.txt") as f:
|
9 |
+
hitchhikersguide = f.read()
|
10 |
+
|
11 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0, separator = "\n")
|
12 |
+
texts = text_splitter.split_text(hitchhikersguide)
|
13 |
+
|
14 |
+
embeddings = OpenAIEmbeddings()
|
15 |
+
|
16 |
+
docsearch = Chroma.from_texts(texts, embeddings, metadatas=[{"source": str(i)} for i in range(len(texts))]).as_retriever()
|
17 |
+
|
18 |
+
chain = load_qa_chain(OpenAI(temperature=0), chain_type="stuff")
|
19 |
+
|
20 |
+
def make_inference(query):
|
21 |
+
docs = docsearch.get_relevant_documents(query)
|
22 |
+
return(chain.run(input_documents=docs, question=query))
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
# make a gradio interface
|
26 |
+
import gradio as gr
|
27 |
+
|
28 |
+
gr.Interface(
|
29 |
+
make_inference,
|
30 |
+
[
|
31 |
+
gr.inputs.Textbox(lines=2, label="Query"),
|
32 |
+
],
|
33 |
+
gr.outputs.Textbox(label="Response"),
|
34 |
+
title="🗣️TalkToMyDoc📄",
|
35 |
+
description="🗣️TalkToMyDoc📄 is a tool that allows you to ask questions about a document. In this case - Hitch Hitchhiker's Guide to the Galaxy.",
|
36 |
+
).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
|