Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,89 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def respond(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
+
import uuid
|
| 5 |
+
import modelscope_studio.components.antd as antd
|
| 6 |
+
import modelscope_studio.components.antdx as antdx
|
| 7 |
+
import modelscope_studio.components.base as ms
|
| 8 |
|
| 9 |
|
| 10 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 11 |
|
| 12 |
+
qwen_logo = os.path.join(os.path.dirname(__file__), "qwen.png")
|
| 13 |
+
|
| 14 |
+
DEFAULT_PROMPTS = [{
|
| 15 |
+
"category":
|
| 16 |
+
"🖋 Make a plan",
|
| 17 |
+
"prompts": [
|
| 18 |
+
"Help me with a plan to start a business",
|
| 19 |
+
"Help me with a plan to achieve my goals",
|
| 20 |
+
"Help me with a plan for a successful interview"
|
| 21 |
+
]
|
| 22 |
+
}, {
|
| 23 |
+
"category":
|
| 24 |
+
"📅 Help me write",
|
| 25 |
+
"prompts": [
|
| 26 |
+
"Help me write a story with a twist ending",
|
| 27 |
+
"Help me write a blog post on mental health",
|
| 28 |
+
"Help me write a letter to my future self"
|
| 29 |
+
]
|
| 30 |
+
}]
|
| 31 |
+
|
| 32 |
+
DEFAULT_SUGGESTIONS = [{
|
| 33 |
+
"label":
|
| 34 |
+
'Make a plan',
|
| 35 |
+
"value":
|
| 36 |
+
"Make a plan",
|
| 37 |
+
"children": [{
|
| 38 |
+
"label": "Start a business",
|
| 39 |
+
"value": "Help me with a plan to start a business"
|
| 40 |
+
}, {
|
| 41 |
+
"label": "Achieve my goals",
|
| 42 |
+
"value": "Help me with a plan to achieve my goals"
|
| 43 |
+
}, {
|
| 44 |
+
"label": "Successful interview",
|
| 45 |
+
"value": "Help me with a plan for a successful interview"
|
| 46 |
+
}]
|
| 47 |
+
}, {
|
| 48 |
+
"label":
|
| 49 |
+
'Help me write',
|
| 50 |
+
"value":
|
| 51 |
+
"Help me write",
|
| 52 |
+
"children": [{
|
| 53 |
+
"label": "Story with a twist ending",
|
| 54 |
+
"value": "Help me write a story with a twist ending"
|
| 55 |
+
}, {
|
| 56 |
+
"label": "Blog post on mental health",
|
| 57 |
+
"value": "Help me write a blog post on mental health"
|
| 58 |
+
}, {
|
| 59 |
+
"label": "Letter to my future self",
|
| 60 |
+
"value": "Help me write a letter to my future self"
|
| 61 |
+
}]
|
| 62 |
+
}]
|
| 63 |
+
|
| 64 |
+
DEFAULT_CONVERSATIONS_HISTORY = [{"role": "placeholder"}]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
DEFAULT_THEME = {
|
| 68 |
+
"token": {
|
| 69 |
+
"colorPrimary": "#6A57FF",
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def format_history(history):
|
| 75 |
+
messages = [{
|
| 76 |
+
"role": "system",
|
| 77 |
+
"content": "You are a helpful and harmless assistant.",
|
| 78 |
+
}]
|
| 79 |
+
for item in history:
|
| 80 |
+
if item["role"] == "user":
|
| 81 |
+
messages.append({"role": "user", "content": item["content"]})
|
| 82 |
+
elif item["role"] == "assistant":
|
| 83 |
+
messages.append({"role": "assistant", "content": item["content"]})
|
| 84 |
+
return messages
|
| 85 |
+
|
| 86 |
+
|
| 87 |
|
| 88 |
|
| 89 |
def respond(
|