Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from langchain_openai import ChatOpenAI # โ
์ต์ ํจํค์ง
|
| 4 |
-
from langchain.
|
| 5 |
-
from langchain.memory import
|
| 6 |
from langchain.prompts import PromptTemplate
|
| 7 |
|
| 8 |
def chatgpt(api_key, prompts, background="You are a dream interpreter."):
|
|
@@ -11,20 +11,22 @@ def chatgpt(api_key, prompts, background="You are a dream interpreter."):
|
|
| 11 |
if not api_key:
|
| 12 |
return "Error: API Key is missing. Please set OPENAI_API_KEY in your environment variables."
|
| 13 |
|
| 14 |
-
# โ
์ต์ LangChain ๋ฐฉ์
|
| 15 |
-
chatgpt_chain =
|
| 16 |
-
|
|
|
|
| 17 |
input_variables=["history", "human_input"],
|
| 18 |
template=background + "\n{history}\nHuman: {human_input}\nDream Interpreter:"
|
| 19 |
-
)
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
-
return chatgpt_chain.
|
| 23 |
|
| 24 |
except Exception as e:
|
| 25 |
return f"Error: {str(e)}"
|
| 26 |
|
| 27 |
-
# โ
Gradio
|
| 28 |
background_input = gr.Textbox(label="Background", value="You are a dream interpreter.")
|
| 29 |
api_key_input = gr.Textbox(label="Enter Your API Key", type="password")
|
| 30 |
user_prompt_input = gr.Textbox(label="Your Prompt")
|
|
@@ -37,4 +39,4 @@ iface = gr.Interface(
|
|
| 37 |
)
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
iface.launch(server_name="0.0.0.0", server_port=7860) # โ
debug=True ์ ๊ฑฐ
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
from langchain_openai import ChatOpenAI # โ
์ต์ ํจํค์ง ์ ์ฉ
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
+
from langchain.memory import ConversationBufferWindowMemory
|
| 6 |
from langchain.prompts import PromptTemplate
|
| 7 |
|
| 8 |
def chatgpt(api_key, prompts, background="You are a dream interpreter."):
|
|
|
|
| 11 |
if not api_key:
|
| 12 |
return "Error: API Key is missing. Please set OPENAI_API_KEY in your environment variables."
|
| 13 |
|
| 14 |
+
# โ
์ต์ LangChain ๋ฐฉ์์ผ๋ก ์์
|
| 15 |
+
chatgpt_chain = LLMChain(
|
| 16 |
+
llm=ChatOpenAI(temperature=0, openai_api_key=api_key),
|
| 17 |
+
prompt=PromptTemplate(
|
| 18 |
input_variables=["history", "human_input"],
|
| 19 |
template=background + "\n{history}\nHuman: {human_input}\nDream Interpreter:"
|
| 20 |
+
),
|
| 21 |
+
memory=ConversationBufferWindowMemory(k=2),
|
| 22 |
)
|
| 23 |
|
| 24 |
+
return chatgpt_chain.predict(human_input=prompts) # โ
predict() ์ฌ์ฉ
|
| 25 |
|
| 26 |
except Exception as e:
|
| 27 |
return f"Error: {str(e)}"
|
| 28 |
|
| 29 |
+
# โ
Gradio UI ์ค์
|
| 30 |
background_input = gr.Textbox(label="Background", value="You are a dream interpreter.")
|
| 31 |
api_key_input = gr.Textbox(label="Enter Your API Key", type="password")
|
| 32 |
user_prompt_input = gr.Textbox(label="Your Prompt")
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
+
iface.launch(server_name="0.0.0.0", server_port=7860) # โ
debug=True ์ ๊ฑฐ
|