NeuralJunkie commited on
Commit
2d420ee
·
1 Parent(s): b6eb6e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -25
app.py CHANGED
@@ -1,29 +1,20 @@
1
  import gradio as gr
2
- from transformers import Conversation, pipeline
3
- from wolframclient.evaluation import WolframLanguageSession
4
- from wolframclient.language import wl, wlexpr
5
 
6
- # Initialize Hugging Face model
7
- conversational_pipeline = pipeline("text2text-generation", model="EleutherAI/chatgpt-3.5-turbo")
8
 
9
- # Initialize Wolfram session
10
- wolfram_session = WolframLanguageSession()
11
- wolfram_session.start()
 
 
 
 
 
 
 
 
 
 
12
 
13
- def chat_with_gpt3_and_wolfram(input_text):
14
- # Create a conversation with the input text
15
- conversation = Conversation(input_text)
16
-
17
- # Generate a response using the Hugging Face model
18
- response = conversational_pipeline(conversation)
19
-
20
- # If the response contains a question, use the Wolfram API to answer it
21
- if "?" in response:
22
- wolfram_response = wolfram_session.evaluate(wl.WolframAlpha(response, "Result"))
23
- return wolfram_response
24
- else:
25
- return response
26
-
27
- # Create Gradio interface
28
- iface = gr.Interface(fn=chat_with_gpt3_and_wolfram, inputs="text", outputs="text")
29
- iface.launch()
 
1
  import gradio as gr
2
+ import wolframalpha
 
 
3
 
4
+ app = gr.App(title="Math Teacher", description="A simple math teacher that can help you solve math problems.")
 
5
 
6
+ @app.callback(
7
+ output="text",
8
+ inputs="text",
9
+ )
10
+ def solve_math_problem(math_problem):
11
+ """Solve a math problem using Wolfram Alpha."""
12
+ app_id = "" # Your Wolfram Alpha App ID token here
13
+ client = wolframalpha.Client(app_id)
14
+ try:
15
+ result = client.query(math_problem)
16
+ return result.pods[0].text
17
+ except Exception:
18
+ return "Sorry, I couldn't solve your math problem."
19
 
20
+ app.launch()