Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,14 @@
|
|
1 |
-
#!/usr/bin/env python3
|
2 |
-
|
3 |
-
import os
|
4 |
import gradio as gr
|
5 |
-
|
6 |
-
import
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
aws_access_key_id = os.environ['AWS_ACCESS_KEY_ID']
|
12 |
-
aws_secret_access_key = os.environ['AWS_SECRET_ACCESS_KEY']
|
13 |
|
14 |
-
|
15 |
-
from langchain.agents import load_tools, Tool, initialize_agent
|
16 |
-
from langchain.llms import OpenAI
|
17 |
-
from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
|
18 |
-
from langchain.agents import initialize_agent, Tool
|
19 |
-
from langchain import OpenAI, LLMChain
|
20 |
-
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader
|
21 |
|
22 |
-
index = GPTSimpleVectorIndex.load_from_disk('index.json')
|
23 |
|
24 |
def querying_db(query: str):
|
25 |
response = index.query(query)
|
@@ -33,7 +22,6 @@ tools = [
|
|
33 |
description="useful for when you need to answer questions from the database. The answer is given in bullet points.",
|
34 |
return_direct=True
|
35 |
)
|
36 |
-
|
37 |
]
|
38 |
|
39 |
prefix = """Give a detailed answer to the question"""
|
@@ -48,6 +36,7 @@ prompt = ZeroShotAgent.create_prompt(
|
|
48 |
suffix=suffix,
|
49 |
input_variables=["input", "agent_scratchpad"]
|
50 |
)
|
|
|
51 |
llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt)
|
52 |
tool_names = [tool.name for tool in tools]
|
53 |
agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names)
|
@@ -59,10 +48,12 @@ def get_answer(query_string):
|
|
59 |
|
60 |
return result
|
61 |
|
|
|
62 |
def qa_app(query):
|
63 |
-
|
64 |
-
return answer
|
65 |
|
66 |
inputs = gr.inputs.Textbox(label="Enter your question:")
|
67 |
output = gr.outputs.Textbox(label="Answer:")
|
68 |
-
gr.Interface(fn=qa_app, inputs=inputs, outputs=output, title="
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
from llama_index import GPTSimpleVectorIndex
|
4 |
+
from langchain.agents import ZeroShotAgent, AgentExecutor
|
5 |
+
from langchain.agents import Tool
|
6 |
+
from langchain import OpenAI, LLMChain
|
7 |
|
8 |
+
os.environ['OPENAI_API_KEY'] = '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'
|
|
|
|
|
9 |
|
10 |
+
index = GPTSimpleVectorIndex.load_from_disk('/mnt/index/comboindex.json')
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
|
|
12 |
|
13 |
def querying_db(query: str):
|
14 |
response = index.query(query)
|
|
|
22 |
description="useful for when you need to answer questions from the database. The answer is given in bullet points.",
|
23 |
return_direct=True
|
24 |
)
|
|
|
25 |
]
|
26 |
|
27 |
prefix = """Give a detailed answer to the question"""
|
|
|
36 |
suffix=suffix,
|
37 |
input_variables=["input", "agent_scratchpad"]
|
38 |
)
|
39 |
+
|
40 |
llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt)
|
41 |
tool_names = [tool.name for tool in tools]
|
42 |
agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names)
|
|
|
48 |
|
49 |
return result
|
50 |
|
51 |
+
|
52 |
def qa_app(query):
|
53 |
+
return get_answer(query)
|
|
|
54 |
|
55 |
inputs = gr.inputs.Textbox(label="Enter your question:")
|
56 |
output = gr.outputs.Textbox(label="Answer:")
|
57 |
+
iface = gr.Interface(fn=qa_app, inputs=inputs, outputs=output, title="Endo AI : Endocrine answering app by Dr. Om J Lakhani")
|
58 |
+
|
59 |
+
iface.launch()
|