Spaces:
Runtime error
Runtime error
File size: 2,400 Bytes
ec36bd2 0d58bdf ec36bd2 5a5f604 ec36bd2 5a5f604 ec36bd2 5a5f604 0d58bdf ec36bd2 0d58bdf ec36bd2 b42d837 f657b0f ec36bd2 0d58bdf ec36bd2 0d58bdf ec36bd2 0d58bdf 5a5f604 0d58bdf ec36bd2 0d58bdf ec36bd2 0d58bdf ec36bd2 0d58bdf ec36bd2 0d58bdf ec36bd2 0d58bdf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import logging
import os
import gradio as gr
from langchain.chat_models import ChatOpenAI
from metaanalyser.chains import SRChain
logger = logging.getLogger(__name__)
logging.basicConfig()
logging.getLogger("metaanalyser").setLevel(level=logging.DEBUG)
def run(query: str, chain: SRChain):
if "OPENAI_API_KEY" in os.environ or "SERPAPI_API_KEY" not in os.environ:
raise gr.Error(f"Please paste your OpenAI (https://platform.openai.com/) key and SerpAPI (https://serpapi.com/) key to use.")
llm = ChatOpenAI(temperature=0)
chain = SRChain(llm=llm, verbose=True)
return chain.run({"query": query})
def set_openai_api_key(api_key: str):
os.environ["OPENAI_API_KEY"] = api_key
def set_serpapi_api_key(api_key: str):
os.environ["SERPAPI_API_KEY"] = api_key
block = gr.Blocks()
with block:
with gr.Row():
gr.Markdown("""
<h2><center>Metaanalyser demo</center></h2>
Generate a systematic review for your query based on Google Scholar search results. See [README](https://github.com/p-baleine/metaanalyser) for details
""")
openai_api_key_textbox = gr.Textbox(
placeholder="Paste your OpenAI API key (sk-...)",
show_label=False,
lines=1,
type="password",
)
serpai_api_key_textbox = gr.Textbox(
placeholder="Paste your SerpApi API key",
show_label=False,
lines=1,
type="password",
)
with gr.Row():
query = gr.Textbox(
label="Query",
placeholder="the query for Google Scholar",
lines=1,
)
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
gr.Examples(
examples=[
"llm agent OR llm tool integration",
],
inputs=query,
)
with gr.Row():
output = gr.Markdown("It will take a few minutes to output the results...")
gr.HTML(
"<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain 🦜️🔗</a></center>"
)
submit.click(fn=run, inputs=query, outputs=output)
openai_api_key_textbox.change(
set_openai_api_key,
inputs=[openai_api_key_textbox],
)
serpai_api_key_textbox.change(
set_serpapi_api_key,
inputs=[serpai_api_key_textbox],
)
block.launch(debug=True)
|