Spaces:
Sleeping
Sleeping
Commit
·
c7e153e
1
Parent(s):
749fee8
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
-
import streamlit as st
|
| 3 |
from langchain import PromptTemplate, LLMChain
|
| 4 |
from langchain.memory import StreamlitChatMessageHistory
|
| 5 |
-
from streamlit_chat import message
|
| 6 |
import numpy as np
|
| 7 |
from langchain.chains import LLMChain
|
| 8 |
from langchain.prompts import PromptTemplate
|
| 9 |
from langchain.memory import ConversationBufferMemory
|
| 10 |
from langchain.memory.chat_message_histories import StreamlitChatMessageHistory
|
| 11 |
-
from streamlit.components.v1 import html
|
| 12 |
from langchain import HuggingFaceHub
|
| 13 |
import os
|
| 14 |
from dotenv import load_dotenv
|
|
@@ -20,15 +20,15 @@ import requests
|
|
| 20 |
#from time import sleep
|
| 21 |
import uuid
|
| 22 |
import sys
|
| 23 |
-
from streamlit_extras.colored_header import colored_header
|
| 24 |
-
from streamlit_extras.add_vertical_space import add_vertical_space
|
| 25 |
|
| 26 |
-
st.set_page_config(page_title="AI Chatbot 100% Free", layout="wide")
|
| 27 |
-
st.write('完全开源免费的AI智能聊天助手 | Absolute Free & Opensouce AI Chatbot')
|
| 28 |
|
| 29 |
-
css_file = "main.css"
|
| 30 |
-
with open(css_file) as f:
|
| 31 |
-
st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
|
| 32 |
|
| 33 |
# 初始化Chatbot
|
| 34 |
HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')
|
|
@@ -57,7 +57,7 @@ assistant:
|
|
| 57 |
|
| 58 |
llm_chain = LLMChain(llm=llm, prompt=PromptTemplate.from_template(prompt_template))
|
| 59 |
|
| 60 |
-
temp_user_query = st.chat_input("Enter your question here.")
|
| 61 |
|
| 62 |
# 定义API端点
|
| 63 |
app = Flask(__name__)
|
|
@@ -67,13 +67,14 @@ def chat():
|
|
| 67 |
#user_query = data['query']
|
| 68 |
#此处的['query']中的query可以自定义名称,例如修改为user_question,那么调用API的代码中,需要相应的使用data = {'user_question': user_query},user_question需一致
|
| 69 |
user_query = data['user_question']
|
| 70 |
-
temp_user_query=user_query
|
| 71 |
# 调用Chatbot
|
| 72 |
initial_response = llm_chain.run(user_query)
|
| 73 |
-
st.write("AI Response")
|
| 74 |
-
st.write(initial_response)
|
| 75 |
return jsonify({'response': initial_response})
|
| 76 |
|
| 77 |
if __name__ == '__main__':
|
| 78 |
#app.run(host='0.0.0.0', port=port)
|
| 79 |
-
app.run(host='0.0.0.0')
|
|
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
+
#import streamlit as st
|
| 3 |
from langchain import PromptTemplate, LLMChain
|
| 4 |
from langchain.memory import StreamlitChatMessageHistory
|
| 5 |
+
#from streamlit_chat import message
|
| 6 |
import numpy as np
|
| 7 |
from langchain.chains import LLMChain
|
| 8 |
from langchain.prompts import PromptTemplate
|
| 9 |
from langchain.memory import ConversationBufferMemory
|
| 10 |
from langchain.memory.chat_message_histories import StreamlitChatMessageHistory
|
| 11 |
+
#from streamlit.components.v1 import html
|
| 12 |
from langchain import HuggingFaceHub
|
| 13 |
import os
|
| 14 |
from dotenv import load_dotenv
|
|
|
|
| 20 |
#from time import sleep
|
| 21 |
import uuid
|
| 22 |
import sys
|
| 23 |
+
#from streamlit_extras.colored_header import colored_header
|
| 24 |
+
#from streamlit_extras.add_vertical_space import add_vertical_space
|
| 25 |
|
| 26 |
+
#st.set_page_config(page_title="AI Chatbot 100% Free", layout="wide")
|
| 27 |
+
#st.write('完全开源免费的AI智能聊天助手 | Absolute Free & Opensouce AI Chatbot')
|
| 28 |
|
| 29 |
+
#css_file = "main.css"
|
| 30 |
+
#with open(css_file) as f:
|
| 31 |
+
# st.markdown("<style>{}</style>".format(f.read()), unsafe_allow_html=True)
|
| 32 |
|
| 33 |
# 初始化Chatbot
|
| 34 |
HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')
|
|
|
|
| 57 |
|
| 58 |
llm_chain = LLMChain(llm=llm, prompt=PromptTemplate.from_template(prompt_template))
|
| 59 |
|
| 60 |
+
#temp_user_query = st.chat_input("Enter your question here.")
|
| 61 |
|
| 62 |
# 定义API端点
|
| 63 |
app = Flask(__name__)
|
|
|
|
| 67 |
#user_query = data['query']
|
| 68 |
#此处的['query']中的query可以自定义名称,例如修改为user_question,那么调用API的代码中,需要相应的使用data = {'user_question': user_query},user_question需一致
|
| 69 |
user_query = data['user_question']
|
| 70 |
+
#temp_user_query=user_query
|
| 71 |
# 调用Chatbot
|
| 72 |
initial_response = llm_chain.run(user_query)
|
| 73 |
+
#st.write("AI Response")
|
| 74 |
+
#st.write(initial_response)
|
| 75 |
return jsonify({'response': initial_response})
|
| 76 |
|
| 77 |
if __name__ == '__main__':
|
| 78 |
#app.run(host='0.0.0.0', port=port)
|
| 79 |
+
#app.run(host='0.0.0.0')
|
| 80 |
+
uvicorn.run(app, host='0.0.0.0')
|