Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,16 @@ import json
|
|
| 6 |
# ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
|
| 8 |
def respond(message, history, max_tokens=512, temperature=0.7, top_p=0.95):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
data = {
|
| 10 |
"model": "jinjavis:latest",
|
| 11 |
-
"prompt":
|
| 12 |
"max_tokens": max_tokens,
|
| 13 |
"temperature": temperature,
|
| 14 |
"top_p": top_p
|
|
@@ -31,7 +38,8 @@ def respond(message, history, max_tokens=512, temperature=0.7, top_p=0.95):
|
|
| 31 |
print(f"Failed to decode JSON: {e}")
|
| 32 |
yield "An error occurred while processing your request."
|
| 33 |
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
demo = gr.ChatInterface(
|
| 37 |
fn=respond,
|
|
@@ -44,4 +52,4 @@ demo = gr.ChatInterface(
|
|
| 44 |
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
demo.queue(max_size=10).launch()
|
|
|
|
| 6 |
# ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
|
| 8 |
def respond(message, history, max_tokens=512, temperature=0.7, top_p=0.95):
|
| 9 |
+
# 대화 이력을 포함한 프롬프트 구성
|
| 10 |
+
if history:
|
| 11 |
+
prompt = "\n".join([f"User: {msg}" for msg, _ in history] + [f"Assistant: {res}" for _, res in history])
|
| 12 |
+
prompt += f"\nUser: {message}\nAssistant:"
|
| 13 |
+
else:
|
| 14 |
+
prompt = f"User: {message}\nAssistant:"
|
| 15 |
+
|
| 16 |
data = {
|
| 17 |
"model": "jinjavis:latest",
|
| 18 |
+
"prompt": prompt,
|
| 19 |
"max_tokens": max_tokens,
|
| 20 |
"temperature": temperature,
|
| 21 |
"top_p": top_p
|
|
|
|
| 38 |
print(f"Failed to decode JSON: {e}")
|
| 39 |
yield "An error occurred while processing your request."
|
| 40 |
|
| 41 |
+
# history 업데이트
|
| 42 |
+
history.append((message, partial_message))
|
| 43 |
|
| 44 |
demo = gr.ChatInterface(
|
| 45 |
fn=respond,
|
|
|
|
| 52 |
)
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
+
demo.queue(max_size=10).launch()
|