Spaces:
Runtime error
Runtime error
File size: 1,794 Bytes
3c2df7b 0973288 02bd76d 7f8aa90 3c2df7b 7f8aa90 3c2df7b 0973288 02bd76d 3c2df7b 78ca3ce 7f8aa90 3c2df7b 7f8aa90 3c2df7b 7f8aa90 3c2df7b 0161628 3c2df7b 0161628 7f8aa90 3c2df7b d8f8a95 | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import os
os.environ["OPENAI_API_KEY"] = os.getenv('open_ai')
os.environ["GOOGLE_API_KEY"] = os.getenv('gemini')
from langchain_google_genai import ChatGoogleGenerativeAI
gemini_model = ChatGoogleGenerativeAI(model = "gemini-pro")
os.environ["WOLFRAM_ALPHA_APPID"] = os.getenv('wolfram')
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
wolfram = WolframAlphaAPIWrapper()
wolfram.run("What is 2x+5 = -3x + 7?")
"""## Standard Tool"""
import google.generativeai as genai
import gradio as gr
def get_completion(text):
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(text)
return response.text
def extract_query(input_text):
prompt_sum = f'''Given input {input_text} from the user, generate a input query that can be input to the WolframAlphaAPIWrapper() method. If
the given input from the user is good as it is, then just output it as it is. If not, regenerate a query that WolframAlphaAPIWrapper() would
understand. You just need output the final query.'''
result = get_completion(prompt_sum)
return result
# Define your davinci_output function
def davinci_output(input_text):
# Add your code here to process the input and generate the output
wolf_query = extract_query(input_text)
output_text = wolfram.run(wolf_query)
return output_text
examples = [
["what is (4.5*2.1)^2.2?"],
["Calculate 73*2-3*4"],
["What is square root of 89898998"]
]
# Create the Gradio interface
iface = gr.Interface(fn=davinci_output, inputs=gr.inputs.Textbox(placeholder="Enter the math problem"), outputs="text", title="Ask DaVinci",
description="Enter a math problem and see the genius of Leonardo DaVinci in action!",examples=examples)
# Run the Gradio app
iface.launch() |