NeuralJunkie commited on
Commit
372013f
·
1 Parent(s): ebd70cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -1,24 +1,29 @@
1
  import gradio as gr
2
- import chatGPT
3
- import wolframalpha
 
4
 
5
- # Create a ChatGPT instance
6
- chatGPT_model = chatGPT.ChatGPT()
7
 
8
- # Create a Wolfram Alpha API instance
9
- wolframalpha_client = wolframalpha.Client()
 
10
 
11
- # Define the gradio app
12
- @gr.app(title="ChatGPT with Wolfram Alpha", description="A chat app that uses ChatGPT and Wolfram Alpha")
13
- def chat_with_wolframalpha(text):
14
- # Get the response from ChatGPT
15
- gpt_response = chatGPT_model.generate_response(text)
16
 
17
- # Ask Wolfram Alpha for the answer to the question
18
- wolfram_response = wolframalpha_client.query(gpt_response)
19
 
20
- # Return the combined response
21
- return gpt_response, wolfram_response
 
 
 
 
22
 
23
- # Run the gradio app
24
- gr.server(chat_with_wolframalpha, port=8000)
 
 
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()