-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
boyjiangboyu
committed
Dec 23, 2023
1 parent
f30e6f7
commit cd18d9f
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import streamlit as st | ||
import sys | ||
import os | ||
from dotenv import load_dotenv | ||
from libs.llms import openai_streaming | ||
from apps.chatbot import get_chatbot_page | ||
sys.path.append(os.path.abspath('..')) | ||
load_dotenv() | ||
|
||
if 'user_input' not in st.session_state: | ||
st.session_state.user_input = "" | ||
|
||
if 'study_tate' not in st.session_state: | ||
st.session_state.study_tate = {} | ||
|
||
# 创建侧边栏 | ||
sidebar = st.sidebar | ||
if sidebar.button('输入单词'): | ||
st.markdown('输入一个单词') | ||
user_input = st.text_input('请输入一个单词') | ||
|
||
|
||
if st.button("开始学习"): | ||
with st.spinner("生成中..."): | ||
msg = f""" | ||
请按照翻译用户输入的单词或中文,如果输入中文就直接翻译为英文,一定要有中文的提示 | ||
输出这个单词个各个形式与时态与例句 | ||
内容短小精悍 | ||
单词是:{user_input} | ||
""" | ||
response = openai_streaming(msg,[]) | ||
placeholder = st.empty() | ||
full_response = '' | ||
for item in response: | ||
text = item.content | ||
if text is not None: | ||
full_response += text | ||
placeholder.markdown(full_response) | ||
placeholder.markdown(full_response) | ||
st.session_state.study_tate[user_input]=full_response | ||
|
||
if user_input not in '': | ||
st.session_state.user_input=user_input | ||
|
||
infobox = st.empty() | ||
|
||
key = st.sidebar.selectbox('单词列表',st.session_state.study_tate.keys()) | ||
|
||
if st.sidebar.button("显示") and key is not None: | ||
infobox.markdown(st.session_state.study_tate[key]) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|