import gradio as gr import os from langchain import OpenAI, PromptTemplate, LLMChain def get_response(question, openai_api_key): os.environ["OPENAI_API_KEY"] = openai_api_key llm = OpenAI(model_name="text-davinci-003") template = 'question:{question}' prompt = PromptTemplate(template=template, input_variables=["question"]) chain = LLMChain(llm=llm,prompt=prompt) response=chain.run(question) return response demo = gr.Interface( fn=get_response, inputs=[ gr.Textbox(label="Question:"), gr.Textbox(label="OpenAI API KEY:", placeholder="sk-...", type="password") ], outputs=[ gr.Textbox(label="Output:") ], title="Langchain Demo" ) demo.launch()