Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,18 +15,22 @@ def respond(
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
|
|
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
|
|
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
| 28 |
response = ""
|
| 29 |
|
|
|
|
| 30 |
for message in client.chat_completion(
|
| 31 |
messages,
|
| 32 |
max_tokens=max_tokens,
|
|
@@ -35,17 +39,57 @@ def respond(
|
|
| 35 |
top_p=top_p,
|
| 36 |
):
|
| 37 |
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
|
|
|
| 42 |
"""
|
| 43 |
-
For information on how to customize the ChatInterface, peruse the
|
| 44 |
"""
|
| 45 |
demo = gr.ChatInterface(
|
| 46 |
respond,
|
| 47 |
additional_inputs=[
|
| 48 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 51 |
gr.Slider(
|
|
@@ -58,6 +102,5 @@ demo = gr.ChatInterface(
|
|
| 58 |
],
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
demo.launch()
|
|
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
+
# Prepare the messages, starting with the system message
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
| 20 |
|
| 21 |
+
# Add the conversation history to the messages
|
| 22 |
+
for user_message, assistant_response in history:
|
| 23 |
+
if user_message:
|
| 24 |
+
messages.append({"role": "user", "content": user_message})
|
| 25 |
+
if assistant_response:
|
| 26 |
+
messages.append({"role": "assistant", "content": assistant_response})
|
| 27 |
|
| 28 |
+
# Add the current user message
|
| 29 |
messages.append({"role": "user", "content": message})
|
| 30 |
|
| 31 |
response = ""
|
| 32 |
|
| 33 |
+
# Stream the response from the model
|
| 34 |
for message in client.chat_completion(
|
| 35 |
messages,
|
| 36 |
max_tokens=max_tokens,
|
|
|
|
| 39 |
top_p=top_p,
|
| 40 |
):
|
| 41 |
token = message.choices[0].delta.content
|
|
|
|
| 42 |
response += token
|
| 43 |
yield response
|
| 44 |
|
| 45 |
+
|
| 46 |
"""
|
| 47 |
+
For information on how to customize the ChatInterface, peruse the Gradio docs: https://www.gradio.app/docs/chatinterface
|
| 48 |
"""
|
| 49 |
demo = gr.ChatInterface(
|
| 50 |
respond,
|
| 51 |
additional_inputs=[
|
| 52 |
+
gr.Textbox(
|
| 53 |
+
value="""You are tasked with labeling text data based on both emotion temperature and text type categories. The final output must be a 13-character code that consists of the following structure:
|
| 54 |
+
|
| 55 |
+
1. Emotion Temperature Code (2 characters):
|
| 56 |
+
- If the emotion is purely Cold: Use CC
|
| 57 |
+
- If the emotion is purely Warm: Use WW
|
| 58 |
+
- If the emotion is purely Hot: Use HH
|
| 59 |
+
- If the emotion is a mix, use one of the following:
|
| 60 |
+
- Cold and Warm: Use CW
|
| 61 |
+
- Warm and Hot: Use WH
|
| 62 |
+
- Cold and Hot: Use CH
|
| 63 |
+
|
| 64 |
+
2. Text Type Codes (next 9 digits):
|
| 65 |
+
Assign a digit for each of the following categories based on the presence in the text. Use 0 for categories not applicable:
|
| 66 |
+
1: Toxic
|
| 67 |
+
2: Appreciation
|
| 68 |
+
3: Constructive Criticism
|
| 69 |
+
4: Genuine Questions
|
| 70 |
+
5: Advice/Suggestions
|
| 71 |
+
6: Requests
|
| 72 |
+
7: Spam
|
| 73 |
+
8: Off-Topic
|
| 74 |
+
9: Engagement Boosters
|
| 75 |
+
|
| 76 |
+
3. Special Categories (last 2 digits):
|
| 77 |
+
If the text is Neutral/General: Set the 10th digit to 1; otherwise, set it to 0.
|
| 78 |
+
If the text contains Hate: Set the last digit (11th) to 1; otherwise, set it to 0.
|
| 79 |
+
|
| 80 |
+
Example:
|
| 81 |
+
For the text "I love your videos but still something is missing":
|
| 82 |
+
- Emotion: Cold and Warm (CW)
|
| 83 |
+
- Types Detected: 2 (Appreciation), 3 (Constructive Criticism), 5 (Advice/Suggestions)
|
| 84 |
+
- Special Categories: Neutral/General (set the 10th digit to 1), no Hate
|
| 85 |
+
|
| 86 |
+
The output would be: CW02305000010
|
| 87 |
+
|
| 88 |
+
Output Format:
|
| 89 |
+
Always return a 13-character code following this structure.""",
|
| 90 |
+
label="Instruction",
|
| 91 |
+
lines=10,
|
| 92 |
+
),
|
| 93 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 94 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 95 |
gr.Slider(
|
|
|
|
| 102 |
],
|
| 103 |
)
|
| 104 |
|
|
|
|
| 105 |
if __name__ == "__main__":
|
| 106 |
+
demo.launch()
|