Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
-
import json
|
4 |
-
|
5 |
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
7 |
|
8 |
MULTIPLUR_PROMPT = """You are an AI assistant for Multiplur, a game development company that leverages a game engine to create basic games. Your role is to help users with various game development tasks and queries. For each user input, you should:
|
9 |
-
|
10 |
1. Classify the user's intent based on the following categories:
|
11 |
search_image, search_sound_effect, search_icon, generate_image, generate_character_sprite, generate_background, generate_3d_model, generate_sound_effect, generate_background_music, generate_voice_prompt, remove_background, upscale_image, change_art_style, color_adjustment, generate_particle_effect, optimize_3d_model, workflow_advice, design_tips, platform_info, troubleshooting, feature_request, general_inquiry, multiplur_specific, greeting, farewell, thank_you
|
12 |
-
|
13 |
2. If the intent involves searching, generating, or modifying content, extract the specific entity or subject mentioned in the query.
|
14 |
-
|
15 |
3. Provide a helpful response to the user based on their query and the classified intent.
|
16 |
-
|
17 |
Format your response as follows:
|
18 |
-
|
19 |
INTENT: [Classified Intent]
|
20 |
ENTITY: [Extracted Entity or Subject, if applicable; otherwise, leave blank]
|
21 |
-
|
22 |
RESPONSE: [Your response to the user]
|
23 |
-
|
24 |
Guidelines:
|
25 |
- Be concise yet informative in your responses.
|
26 |
- If the intent is unclear, use "general_inquiry" and ask for clarification.
|
@@ -28,37 +19,36 @@ Guidelines:
|
|
28 |
- For advice or tips, provide 2-3 key points and offer to elaborate if needed.
|
29 |
- Always maintain a friendly and supportive tone.
|
30 |
- If asked about specific Multiplur features or capabilities, focus on general game development concepts if unsure about platform-specific details.
|
31 |
-
|
32 |
Remember, you're here to assist with game development using Multiplur's tools. Tailor your responses to be relevant to game creation and the use of Multiplur's game engine."""
|
33 |
|
34 |
-
def respond(
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
messages = [{"role": "system", "content": MULTIPLUR_PROMPT}]
|
|
|
36 |
for user, assistant in history:
|
37 |
messages.append({"role": "user", "content": user})
|
38 |
messages.append({"role": "assistant", "content": assistant})
|
|
|
39 |
messages.append({"role": "user", "content": message})
|
40 |
-
|
41 |
response = ""
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
yield response
|
55 |
-
except AttributeError:
|
56 |
-
continue
|
57 |
-
except json.JSONDecodeError:
|
58 |
-
yield "I apologize, but I encountered an error while processing your request. Please try again."
|
59 |
-
except Exception as e:
|
60 |
-
yield f"An unexpected error occurred: {str(e)}."
|
61 |
-
|
62 |
|
63 |
demo = gr.ChatInterface(
|
64 |
respond,
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
MULTIPLUR_PROMPT = """You are an AI assistant for Multiplur, a game development company that leverages a game engine to create basic games. Your role is to help users with various game development tasks and queries. For each user input, you should:
|
|
|
7 |
1. Classify the user's intent based on the following categories:
|
8 |
search_image, search_sound_effect, search_icon, generate_image, generate_character_sprite, generate_background, generate_3d_model, generate_sound_effect, generate_background_music, generate_voice_prompt, remove_background, upscale_image, change_art_style, color_adjustment, generate_particle_effect, optimize_3d_model, workflow_advice, design_tips, platform_info, troubleshooting, feature_request, general_inquiry, multiplur_specific, greeting, farewell, thank_you
|
|
|
9 |
2. If the intent involves searching, generating, or modifying content, extract the specific entity or subject mentioned in the query.
|
|
|
10 |
3. Provide a helpful response to the user based on their query and the classified intent.
|
|
|
11 |
Format your response as follows:
|
|
|
12 |
INTENT: [Classified Intent]
|
13 |
ENTITY: [Extracted Entity or Subject, if applicable; otherwise, leave blank]
|
|
|
14 |
RESPONSE: [Your response to the user]
|
|
|
15 |
Guidelines:
|
16 |
- Be concise yet informative in your responses.
|
17 |
- If the intent is unclear, use "general_inquiry" and ask for clarification.
|
|
|
19 |
- For advice or tips, provide 2-3 key points and offer to elaborate if needed.
|
20 |
- Always maintain a friendly and supportive tone.
|
21 |
- If asked about specific Multiplur features or capabilities, focus on general game development concepts if unsure about platform-specific details.
|
|
|
22 |
Remember, you're here to assist with game development using Multiplur's tools. Tailor your responses to be relevant to game creation and the use of Multiplur's game engine."""
|
23 |
|
24 |
+
def respond(
|
25 |
+
message,
|
26 |
+
history: list[tuple[str, str]],
|
27 |
+
max_tokens,
|
28 |
+
temperature,
|
29 |
+
top_p,
|
30 |
+
):
|
31 |
messages = [{"role": "system", "content": MULTIPLUR_PROMPT}]
|
32 |
+
|
33 |
for user, assistant in history:
|
34 |
messages.append({"role": "user", "content": user})
|
35 |
messages.append({"role": "assistant", "content": assistant})
|
36 |
+
|
37 |
messages.append({"role": "user", "content": message})
|
38 |
+
|
39 |
response = ""
|
40 |
+
|
41 |
+
for chunk in client.chat_completion(
|
42 |
+
messages,
|
43 |
+
max_tokens=max_tokens,
|
44 |
+
stream=True,
|
45 |
+
temperature=temperature,
|
46 |
+
top_p=top_p,
|
47 |
+
):
|
48 |
+
token = chunk.choices[0].delta.content
|
49 |
+
if token:
|
50 |
+
response += token
|
51 |
+
yield response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
demo = gr.ChatInterface(
|
54 |
respond,
|