Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
from langchain_community.embeddings import SentenceTransformerEmbeddings
|
4 |
from langchain_community.vectorstores import FAISS
|
5 |
|
@@ -24,7 +24,7 @@ except Exception as e:
|
|
24 |
def answer_question(gemma, temperature, max_length, question):
|
25 |
# 4. 初始化 Gemma 模型
|
26 |
try:
|
27 |
-
llm =
|
28 |
except Exception as e:
|
29 |
st.error(f"Gemma 模型加载失败:{e}")
|
30 |
st.stop()
|
@@ -33,7 +33,7 @@ def answer_question(gemma, temperature, max_length, question):
|
|
33 |
try:
|
34 |
question_embedding = embeddings.embed_query(question)
|
35 |
question_embedding_str = " ".join(map(str, question_embedding))
|
36 |
-
print('question_embedding: ' + question_embedding_str)
|
37 |
docs_and_scores = db.similarity_search_with_score(question_embedding_str)
|
38 |
|
39 |
context = "\n".join([doc.page_content for doc, _ in docs_and_scores])
|
@@ -48,12 +48,12 @@ def answer_question(gemma, temperature, max_length, question):
|
|
48 |
st.error(f"问答过程出错:{e}")
|
49 |
return "An error occurred during the answering process."
|
50 |
|
51 |
-
#
|
52 |
st.title("Gemma 知识库问答系统")
|
53 |
|
54 |
-
gemma = st.selectbox("
|
55 |
-
temperature = st.
|
56 |
-
max_length = st.
|
57 |
question = st.text_area("请输入问题", "Gemma 有哪些特点?")
|
58 |
|
59 |
if st.button("提交"):
|
|
|
1 |
import streamlit as st
|
2 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
3 |
from langchain_community.embeddings import SentenceTransformerEmbeddings
|
4 |
from langchain_community.vectorstores import FAISS
|
5 |
|
|
|
24 |
def answer_question(gemma, temperature, max_length, question):
|
25 |
# 4. 初始化 Gemma 模型
|
26 |
try:
|
27 |
+
llm = HuggingFaceEndpoint(repo_id=gemma, model_kwargs={"temperature": temperature, "max_length": max_length})
|
28 |
except Exception as e:
|
29 |
st.error(f"Gemma 模型加载失败:{e}")
|
30 |
st.stop()
|
|
|
33 |
try:
|
34 |
question_embedding = embeddings.embed_query(question)
|
35 |
question_embedding_str = " ".join(map(str, question_embedding))
|
36 |
+
# print('question_embedding: ' + question_embedding_str)
|
37 |
docs_and_scores = db.similarity_search_with_score(question_embedding_str)
|
38 |
|
39 |
context = "\n".join([doc.page_content for doc, _ in docs_and_scores])
|
|
|
48 |
st.error(f"问答过程出错:{e}")
|
49 |
return "An error occurred during the answering process."
|
50 |
|
51 |
+
# 6. Streamlit 界面
|
52 |
st.title("Gemma 知识库问答系统")
|
53 |
|
54 |
+
gemma = st.selectbox("repo-id", ("google/gemma-2-9b-it", "google/gemma-2-2b-it", "google/recurrentgemma-2b-it"), 2)
|
55 |
+
temperature = st.number_input("temperature", value=1.0)
|
56 |
+
max_length = st.number_input("max_length", value=1024)
|
57 |
question = st.text_area("请输入问题", "Gemma 有哪些特点?")
|
58 |
|
59 |
if st.button("提交"):
|