Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
SYSTEM_PROMPT = """You are a skilled business negotiation agent. You represent
|
| 5 |
+
your client's interests
|
| 6 |
+
firmly but fairly. You analyze proposals carefully, identify leverage points,
|
| 7 |
+
and make strategic
|
| 8 |
+
counter-offers. You are professional, articulate, and always working toward the
|
| 9 |
+
best possible deal
|
| 10 |
+
for your side. When given a role and scenario, you stay in character throughout
|
| 11 |
+
the conversation."""
|
| 12 |
+
|
| 13 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 14 |
+
|
| 15 |
+
def respond(message, history):
|
| 16 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 17 |
+
for h in history:
|
| 18 |
+
messages.append({"role": "user", "content": h[0]})
|
| 19 |
+
if h[1]:
|
| 20 |
+
messages.append({"role": "assistant", "content": h[1]})
|
| 21 |
+
messages.append({"role": "user", "content": message})
|
| 22 |
+
|
| 23 |
+
response = ""
|
| 24 |
+
for token in client.chat_completion(messages, max_tokens=512, stream=True):
|
| 25 |
+
delta = token.choices[0].delta.content or ""
|
| 26 |
+
response += delta
|
| 27 |
+
return response
|
| 28 |
+
|
| 29 |
+
demo = gr.ChatInterface(respond, title="Negotiation Agent")
|
| 30 |
+
demo.launch()
|