Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ["OPENAI_API_KEY"] = os.environ.get("GPT_API_KEY")
|
3 |
+
|
4 |
+
from langchain.chat_models import ChatOpenAI
|
5 |
+
from langchain import ConversationChain
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
# ๋ญ์ฒด์ธ ๋ชจ๋ธ ์ด๊ธฐํ
|
9 |
+
llm = ChatOpenAI(temperature=0, model_name='gpt-4o-mini')
|
10 |
+
conversation = ConversationChain(llm=llm, verbose=True)
|
11 |
+
|
12 |
+
# Gradio ์ฑ๋ด ์๋ต ํจ์
|
13 |
+
def response(message, history):
|
14 |
+
# ๋ญ์ฒด์ธ์ ์ฌ์ฉํ์ฌ ๋ํ ์์ธก
|
15 |
+
response_text = conversation.predict(input=message)
|
16 |
+
return response_text
|
17 |
+
|
18 |
+
# Gradio ์ฑ๋ด ์ธํฐํ์ด์ค ์ค์ ๋ฐ ์คํ
|
19 |
+
gr.ChatInterface(
|
20 |
+
fn=response,
|
21 |
+
type="messages"
|
22 |
+
).launch()
|