Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -30,47 +30,8 @@ text_splitter = RecursiveCharacterTextSplitter(
|
|
30 |
|
31 |
documents = text_splitter.split_documents(data)
|
32 |
|
33 |
-
|
34 |
print("Got docs split")
|
35 |
-
#Input openai api key
|
36 |
-
# Check if the OpenAI API Key is empty
|
37 |
-
def check_api_key(api_key):
|
38 |
-
if api_key == "":
|
39 |
-
return False
|
40 |
-
return True
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
# Create the Gradio interface
|
45 |
-
def gradio_interface(api_key):
|
46 |
-
if not check_api_key(api_key):
|
47 |
-
return "API key is empty. Please provide a valid API key."
|
48 |
-
else:
|
49 |
-
# Create the second page interface
|
50 |
-
question_input = gr.inputs.Textbox(label="Question")
|
51 |
-
answer_output = gr.outputs.Textbox(label="Answer")
|
52 |
-
|
53 |
-
# Function for the second page interface
|
54 |
-
def infer_question(question):
|
55 |
-
answer = make_inference(question)
|
56 |
-
return answer
|
57 |
-
|
58 |
-
# Define the second page of the Gradio interface
|
59 |
-
second_page = gr.Interface(fn=infer_question, inputs=question_input, outputs=answer_output, title="Ask me about Ted Lasso 📺⚽")
|
60 |
-
|
61 |
-
# Launch the second page interface
|
62 |
-
second_page.launch()
|
63 |
-
|
64 |
-
# Define the input interface for the first page (OpenAI API Key entry)
|
65 |
-
api_key_input = gr.inputs.Textbox(label="OpenAI API Key")
|
66 |
-
|
67 |
-
# Create the first page interface
|
68 |
-
first_page = gr.Interface(fn=gradio_interface, inputs=api_key_input, title="OpenAI API Key Entry")
|
69 |
-
|
70 |
-
# Launch the first page interface
|
71 |
-
first_page.launch()
|
72 |
|
73 |
-
print("got API key")
|
74 |
# Create the embeddings
|
75 |
embeddings = OpenAIEmbeddings()
|
76 |
#Load the model
|
@@ -85,10 +46,23 @@ print("Created retriever")
|
|
85 |
#create the QA chain
|
86 |
ted_lasso_qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=doc_retriever)
|
87 |
# Function to make inferences and provide answers
|
88 |
-
def make_inference(
|
89 |
-
# Perform inference using the question and return the answer
|
90 |
print("reached inference")
|
91 |
-
return ted_lasso_qa.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
|
94 |
|
|
|
30 |
|
31 |
documents = text_splitter.split_documents(data)
|
32 |
|
|
|
33 |
print("Got docs split")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
|
|
35 |
# Create the embeddings
|
36 |
embeddings = OpenAIEmbeddings()
|
37 |
#Load the model
|
|
|
46 |
#create the QA chain
|
47 |
ted_lasso_qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=doc_retriever)
|
48 |
# Function to make inferences and provide answers
|
49 |
+
def make_inference(query):
|
|
|
50 |
print("reached inference")
|
51 |
+
return ted_lasso_qa.run(query)
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
# make a gradio interface
|
55 |
+
import gradio as gr
|
56 |
+
|
57 |
+
gr.Interface(
|
58 |
+
make_inference,
|
59 |
+
[
|
60 |
+
gr.inputs.Textbox(lines=2, label="Query"),
|
61 |
+
],
|
62 |
+
gr.outputs.Textbox(label="Response"),
|
63 |
+
title="Ask me about Ted Lasso 📺⚽"
|
64 |
+
description="Ask me about Ted Lasso 📺⚽ is a tool that allows you to ask questions the tv series Ted Lasso",
|
65 |
+
).launch()
|
66 |
|
67 |
|
68 |
|