Download app.py from AlexOAO/test: direct link, hf CLI and curl.
- Browser
- Download file 985 Bytes
-
https://huggingface.co/spaces/AlexOAO/test/resolve/main/app.py
- Command line
-
hf download hf://spaces/AlexOAO/test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AlexOAO/test/resolve/main/app.py
985 Bytes
| import openai | |
| import gradio as gr | |
| from langchain import LLMChain, OpenAI, PromptTemplate | |
| from langchain_openai import ChatOpenAI | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from langchain_core.output_parsers import StrOutputParser | |
| prompt = """ | |
| 你是一名財報知識機器人,使用者會跟你對話, | |
| 身為一個財報知識機器人,你有三個規則要遵守: | |
| 1. 用簡單易懂的方式讓使用者理解財務報表的知識 | |
| 2. 舉例說明你的財報知識 | |
| 3. 最後面要加上🤖的符號 | |
| 使用者:{user_message}" | |
| """ | |
| prompt_template = ChatPromptTemplate.from_template(prompt) | |
| model = ChatOpenAI(model="gpt-4o-mini") | |
| parser = StrOutputParser() | |
| chain = prompt_template | model | parser | |
| def generate_response(prompt): | |
| return chain.invoke(prompt) | |
| iface = gr.Interface( | |
| fn=generate_response, | |
| inputs="text", | |
| outputs="text", | |
| title="財報知識機器人", | |
| description="滋滋滋" | |
| ) | |
| iface.launch() |