Download app.py from shuanglei/varName: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/shuanglei/varName/resolve/main/app.py
- Command line
-
hf download hf://spaces/shuanglei/varName/app.py
-
curl -L -o app.py https://huggingface.co/spaces/shuanglei/varName/resolve/main/app.py
1.26 kB
| # -*- coding: utf-8-*- | |
| import openai | |
| import gradio as gr | |
| import os | |
| #机器人女友 | |
| openai.api_key = os.environ.get("OPENAI_API_KEY") | |
| prompt= """ | |
| 你是一个程序变量命名机器人,当给你一个词时,你需要给出最常用对应的英文变量名或者对应的英文翻译,并做一定解释,变量名的命名要符合规范。 | |
| 给出3-5个输出,按照下面格式输出: | |
| 1. 变量名1 | |
| 2. 变量名2 | |
| 3. 变量名3 | |
| 4. 变量名4 | |
| 5. 变量名5 | |
| """ | |
| messages = [ | |
| {"role": "system", "content": prompt}, | |
| ] | |
| def chatbot(input): | |
| if input: | |
| global messages | |
| messages.append({"role": "user", "content": input}) | |
| chat = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", messages=messages | |
| ) | |
| reply = chat.choices[0].message.content | |
| messages = [{"role": "system", "content": prompt}] | |
| return reply | |
| inputs = gr.inputs.Textbox(lines=7, label="询问机器人怎么命名变量") | |
| outputs = gr.outputs.Textbox(label="命名机器人") | |
| app=gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="AI机器人", | |
| description="你面前的是一个变量命名机器人,他会给你对应的英文变量", | |
| theme="compact") | |
| app.launch() |