Spaces:
Runtime error
Runtime error
Download app.py from shuanglei/universalRobot: direct link, hf CLI and curl.
- Browser
- Download file 924 Bytes
-
https://huggingface.co/spaces/shuanglei/universalRobot/resolve/main/app.py
- Command line
-
hf download hf://spaces/shuanglei/universalRobot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/shuanglei/universalRobot/resolve/main/app.py
924 Bytes
| # -*- coding: utf-8-*- | |
| import openai | |
| import gradio as gr | |
| import os | |
| #机器人女友 | |
| openai.api_key = os.environ.get("OPENAI_API_KEY") | |
| prompt= "You are a helpful assistant." | |
| 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() |