Spaces:
Runtime error
Runtime error
| 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() |