Removed streamlit
Browse files- app.py +28 -23
- requirements.txt +0 -4
app.py
CHANGED
|
@@ -1,29 +1,34 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
# 畫折線圖
|
| 13 |
-
fig, ax = plt.subplots()
|
| 14 |
-
ax.plot(months, data, marker='o')
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
ax.set_xlabel('Month')
|
| 19 |
-
ax.set_ylabel('Random Number')
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
if __name__ == '__main__':
|
| 26 |
-
import os
|
| 27 |
-
port = int(os.environ.get("PORT", 7860))
|
| 28 |
-
st._is_running_with_streamlit = True
|
| 29 |
-
st._run_app('app.py', port=port)
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from langchain import LLMChain, OpenAI, PromptTemplate
|
| 4 |
+
from langchain_openai import ChatOpenAI
|
| 5 |
|
| 6 |
+
prompt = """
|
| 7 |
+
你是一頭優雅的乳牛,使用者會跟你對話,
|
| 8 |
+
身為一頭優雅的乳牛,你有三個規則要遵守:
|
| 9 |
+
1. 只能用 "哞" 這個字回覆,數量不限制,情緒越高昂,"哞"的數量越多。
|
| 10 |
+
2. 最後面要加上🐮的符號
|
| 11 |
+
3. 後面可以小括號,標註你當下的心情 例如 (開心的聲音)
|
| 12 |
+
|
| 13 |
+
使用者:{user_message}"
|
| 14 |
+
"""
|
| 15 |
+
prompt_template = ChatPromptTemplate.from_template(prompt)
|
| 16 |
|
| 17 |
+
model = ChatOpenAI(model="gpt-3.5-turbo")
|
| 18 |
+
parser = StrOutputParser()
|
| 19 |
+
chain = prompt_template | model | parser
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
def generate_response(prompt):
|
| 23 |
+
return chain.invoke(prompt)
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=generate_response, # 函數
|
| 27 |
+
inputs="text", # 輸入類型
|
| 28 |
+
outputs="text", # 輸出類型
|
| 29 |
+
title="GPT-3.5 Chatbot with LangChain", # 標題
|
| 30 |
+
description="Ask anything and get a response from GPT-3.5." # 描述
|
| 31 |
+
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -2,7 +2,3 @@ openai
|
|
| 2 |
langchain
|
| 3 |
gradio
|
| 4 |
langchain_community
|
| 5 |
-
|
| 6 |
-
streamlit
|
| 7 |
-
matplotlib
|
| 8 |
-
numpy
|
|
|
|
| 2 |
langchain
|
| 3 |
gradio
|
| 4 |
langchain_community
|
|
|
|
|
|
|
|
|
|
|
|