Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,6 @@ import os
|
|
| 12 |
'''
|
| 13 |
load_dotenv() # load environment variables from .env file
|
| 14 |
api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
|
| 15 |
-
|
| 16 |
def predict(message, history):
|
| 17 |
prompt = "I'm an AI chatbot named ChatSherman designed by a super-intelligent student named ShermanAI at the Department of Electronic and Information Engineering at The Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions. I am now version 2.0, which is more powerful than version 1.0, able to do more complex tasks, and optimized for chat. "
|
| 18 |
history = [(prompt, '')] + history
|
|
@@ -27,13 +26,11 @@ def predict(message, history):
|
|
| 27 |
temperature=0.5,
|
| 28 |
stream=True
|
| 29 |
)
|
| 30 |
-
|
| 31 |
partial_message = ""
|
| 32 |
for chunk in response:
|
| 33 |
if len(chunk['choices'][0]['delta']) != 0:
|
| 34 |
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
| 35 |
yield partial_message
|
| 36 |
-
|
| 37 |
title = "ChatSherman-2.0"
|
| 38 |
description = "Due to the unavailability of an OpenAI key, this chatbot is currently not operational. I apologize for any inconvenience caused. However, you may try using ChatSherman-1.0 at https://huggingface.co/spaces/ShermanAI/ChatSherman for a similar conversational experience. Thank you for your understanding"#"This is an AI chatbot powered by ShermanAI. Enter your question below to get started. "
|
| 39 |
examples = [
|
|
@@ -42,7 +39,7 @@ examples = [
|
|
| 42 |
["What are some common applications of deep learning in engineering?", []]
|
| 43 |
]
|
| 44 |
gr.ChatInterface(predict, title=title, description=description, examples=examples).queue().launch(debug=True)
|
| 45 |
-
|
| 46 |
|
| 47 |
title = "ChatSherman-2.0"
|
| 48 |
description = ("Due to the unavailability of an OpenAI key, this chatbot is currently not operational. "
|
|
@@ -55,32 +52,4 @@ def show_message():
|
|
| 55 |
|
| 56 |
iface = gr.Interface(fn=show_message, inputs=[], outputs="text", title=title, description=description)
|
| 57 |
|
| 58 |
-
iface.launch(debug=True)
|
| 59 |
-
'''
|
| 60 |
-
|
| 61 |
-
import gradio as gr
|
| 62 |
-
|
| 63 |
-
title = "ChatSherman-2.0"
|
| 64 |
-
description = ("Due to the unavailability of an OpenAI key, this chatbot is currently not operational. I apologize for any inconvenience caused. However, you may try using ChatSherman-1.0 at https://huggingface.co/spaces/ShermanAI/ChatSherman for a similar conversational experience. Thank you for your understanding")
|
| 65 |
-
|
| 66 |
-
# Custom CSS to increase the font size of the description.
|
| 67 |
-
custom_css = """
|
| 68 |
-
<style>
|
| 69 |
-
.markdown-text {
|
| 70 |
-
font-size: 20px;
|
| 71 |
-
}
|
| 72 |
-
</style>
|
| 73 |
-
"""
|
| 74 |
-
|
| 75 |
-
def show_message():
|
| 76 |
-
return description # Simply return the message.
|
| 77 |
-
|
| 78 |
-
# Create a Gradio interface that only shows the message with no interaction, and larger font.
|
| 79 |
-
iface = gr.Interface(
|
| 80 |
-
fn=show_message,
|
| 81 |
-
inputs=[],
|
| 82 |
-
outputs="text",
|
| 83 |
-
title=title,
|
| 84 |
-
description=description,
|
| 85 |
-
css=custom_css # Add the custom CSS here.
|
| 86 |
-
)
|
|
|
|
| 12 |
'''
|
| 13 |
load_dotenv() # load environment variables from .env file
|
| 14 |
api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
|
|
|
|
| 15 |
def predict(message, history):
|
| 16 |
prompt = "I'm an AI chatbot named ChatSherman designed by a super-intelligent student named ShermanAI at the Department of Electronic and Information Engineering at The Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions. I am now version 2.0, which is more powerful than version 1.0, able to do more complex tasks, and optimized for chat. "
|
| 17 |
history = [(prompt, '')] + history
|
|
|
|
| 26 |
temperature=0.5,
|
| 27 |
stream=True
|
| 28 |
)
|
|
|
|
| 29 |
partial_message = ""
|
| 30 |
for chunk in response:
|
| 31 |
if len(chunk['choices'][0]['delta']) != 0:
|
| 32 |
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
| 33 |
yield partial_message
|
|
|
|
| 34 |
title = "ChatSherman-2.0"
|
| 35 |
description = "Due to the unavailability of an OpenAI key, this chatbot is currently not operational. I apologize for any inconvenience caused. However, you may try using ChatSherman-1.0 at https://huggingface.co/spaces/ShermanAI/ChatSherman for a similar conversational experience. Thank you for your understanding"#"This is an AI chatbot powered by ShermanAI. Enter your question below to get started. "
|
| 36 |
examples = [
|
|
|
|
| 39 |
["What are some common applications of deep learning in engineering?", []]
|
| 40 |
]
|
| 41 |
gr.ChatInterface(predict, title=title, description=description, examples=examples).queue().launch(debug=True)
|
| 42 |
+
'''
|
| 43 |
|
| 44 |
title = "ChatSherman-2.0"
|
| 45 |
description = ("Due to the unavailability of an OpenAI key, this chatbot is currently not operational. "
|
|
|
|
| 52 |
|
| 53 |
iface = gr.Interface(fn=show_message, inputs=[], outputs="text", title=title, description=description)
|
| 54 |
|
| 55 |
+
iface.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|