IvanLee commited on
Commit
f34d217
·
1 Parent(s): b2ac5a9

Removed streamlit

Browse files
Files changed (2) hide show
  1. app.py +28 -23
  2. requirements.txt +0 -4
app.py CHANGED
@@ -1,29 +1,34 @@
1
- import streamlit as st
2
- import matplotlib.pyplot as plt
3
- import numpy as np
 
4
 
5
- # 設定頁面標題
6
- st.title('Monthly Random Numbers Line Chart')
 
 
 
 
 
 
 
 
7
 
8
- # 生成隨機數據
9
- months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
10
- data = np.random.randint(0, 100, size=12)
11
 
12
- # 畫折線圖
13
- fig, ax = plt.subplots()
14
- ax.plot(months, data, marker='o')
15
 
16
- # 設置圖表標題和標籤
17
- ax.set_title('Random Numbers for Each Month')
18
- ax.set_xlabel('Month')
19
- ax.set_ylabel('Random Number')
20
 
21
- # 顯示圖表
22
- st.pyplot(fig)
 
 
 
 
 
 
23
 
24
- # 運行 streamlit 應用
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