Spaces:
Runtime error
Runtime error
Commit ·
372013f
1
Parent(s): ebd70cc
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# Get the response from ChatGPT
|
| 15 |
-
gpt_response = chatGPT_model.generate_response(text)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
gr.
|
|
|
|
|
|
| 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()
|