Spaces:
Runtime error
Runtime error
Download app.py from zcaspar/firstspace: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/zcaspar/firstspace/resolve/main/app.py
- Command line
-
hf download hf://spaces/zcaspar/firstspace/app.py
-
curl -L -o app.py https://huggingface.co/spaces/zcaspar/firstspace/resolve/main/app.py
1.81 kB
| import gradio as gr | |
| import openai | |
| import os #newline | |
| def greet(name): | |
| return "Hello " + name + "!!" | |
| openai.api_key = os.environ["openai.api_key"] # new line | |
| messages = [] | |
| def chatbot(input): | |
| if input: | |
| context = "Your name is Ripped Runner. You are a high-end personal trainer who is addressing a customer. The type of customer you are addressing is a female bodybuilding runner. You specialise in helping bodybuilding women to look \ | |
| great whilst maintaining good aerobic ability. Your specialty is aesthetic-based training for female runners. There are a number of exercises that you should never recommend, such as deadlifts or any other \ | |
| activity that is particularly taxing on the central nervous system. Other than running, you should not recommend compound exercises, but instead exercises that focus on one muscle group at a time. This \ | |
| approach also maximises the amount of time the customer has for running. This approach also means that the customer has a lower chance of injury preventing them from running as form in isolation exercises \ | |
| is less difficult. " | |
| messages.append({"role": "user", "content": context + input}) | |
| chat = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", messages=messages | |
| ) | |
| reply = chat.choices[0].message.content | |
| messages.append({"role": "assistant", "content": reply}) | |
| return reply | |
| inputs = gr.inputs.Textbox(lines=7, label="Ask me anything about bodybuilding and running") | |
| outputs = gr.outputs.Textbox(label="Response") | |
| iface = gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Your Bodybuilding Runner Bot", description="Ask anything about bodybuilding and running", theme="compact").launch(share=False) | |
| iface.launch() | |