Spaces:
Runtime error
Runtime error
File size: 1,117 Bytes
4395b89 453dbcd a380611 540f76d 4395b89 540f76d 4395b89 540f76d 4395b89 540f76d 4395b89 540f76d 4395b89 540f76d 4395b89 540f76d 4395b89 d6bab40 540f76d 5262530 540f76d f7a02b6 4395b89 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import openai
import re
import gradio as gr
# Define a function to solve math problems
def solve_math_problem(prompt, api_key):
# Set up the OpenAI API credentials
openai.api_key = api_key
# Send the prompt to OpenAI's GPT-3 engine
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=100,
n=1,
stop=None,
temperature=0.5,
)
# Extract the answer from the response
answer = response.choices[0].text.strip()
# Remove any non-numeric characters from the answer
answer = re.sub("[^0-9\.]", "", answer)
return float(answer)
# Define the Gradio interface
iface = gr.Interface(
fn=solve_math_problem,
inputs=[
gr.inputs.Textbox(label="Enter a math problem"),
gr.inputs.Textbox(label="Enter your OpenAI API key", type="password")
],
outputs=gr.outputs.Textbox(label="Answer"),
title="OpenAI Calculator",
description="Enter a math problem and let OpenAI solve it for you!",
live=True,
button_text="Calculate"
)
# Launch the Gradio interface
iface.launch() |