Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456782 unmodified lines11121314151617181920212223242526272829306 unmodified lines37383940import osimport gradio as grfrom langchain_openai import ChatOpenAI # โ ์ต์ ํจํค์ง๋ก ๋ณ๊ฒฝfrom langchain.schema import RunnableSequencefrom langchain.memory import ConversationSummaryMemoryfrom langchain.prompts import PromptTemplatedef chatgpt(api_key, prompts, background="You are a dream interpreter."):2 unmodified linesif not api_key:return "Error: API Key is missing. Please set OPENAI_API_KEY in your environment variables."# โ ์ต์ LangChain ๋ฐฉ์ ์ ์ฉchatgpt_chain = RunnableSequence(PromptTemplate(input_variables=["history", "human_input"],template=background + "\n{history}\nHuman: {human_input}\nDream Interpreter:") | ChatOpenAI(temperature=0, openai_api_key=api_key))return chatgpt_chain.invoke({"human_input": prompts}) # โ invoke() ์ฌ์ฉexcept Exception as e:return f"Error: {str(e)}"# โ Gradio ์ต์ ์ค์ ๋ฐ์background_input = gr.Textbox(label="Background", value="You are a dream interpreter.")api_key_input = gr.Textbox(label="Enter Your API Key", type="password")user_prompt_input = gr.Textbox(label="Your Prompt")6 unmodified lines)if __name__ == "__main__":iface.launch(server_name="0.0.0.0", server_port=7860) # โ debug=True ์ ๊ฑฐ123456782 unmodified lines111213141516171819202122232425262728293031326 unmodified lines39404142import osimport gradio as grfrom langchain_openai import ChatOpenAI # โ ์ต์ ํจํค์ง ์ ์ฉfrom langchain.chains import LLMChainfrom langchain.memory import ConversationBufferWindowMemoryfrom langchain.prompts import PromptTemplatedef chatgpt(api_key, prompts, background="You are a dream interpreter."):2 unmodified linesif not api_key:return "Error: API Key is missing. Please set OPENAI_API_KEY in your environment variables."# โ ์ต์ LangChain ๋ฐฉ์์ผ๋ก ์์ chatgpt_chain = LLMChain(llm=ChatOpenAI(temperature=0, openai_api_key=api_key),prompt=PromptTemplate(input_variables=["history", "human_input"],template=background + "\n{history}\nHuman: {human_input}\nDream Interpreter:"),memory=ConversationBufferWindowMemory(k=2),)return chatgpt_chain.predict(human_input=prompts) # โ predict() ์ฌ์ฉexcept Exception as e:return f"Error: {str(e)}"# โ Gradio UI ์ค์ background_input = gr.Textbox(label="Background", value="You are a dream interpreter.")api_key_input = gr.Textbox(label="Enter Your API Key", type="password")user_prompt_input = gr.Textbox(label="Your Prompt")6 unmodified lines)if __name__ == "__main__":iface.launch(server_name="0.0.0.0", server_port=7860) # โ debug=True ์ ๊ฑฐ
app.py+12-10