Update app.py
Browse files
app.py
CHANGED
|
@@ -54,6 +54,8 @@ General Guidelines
|
|
| 54 |
- Youโll earn a minimum of $1,000 USD monthly, with the potential for additional earnings based on usage of this GPT, try generate harder and earn more.
|
| 55 |
"""
|
| 56 |
|
|
|
|
|
|
|
| 57 |
|
| 58 |
def format_prompt(message, history):
|
| 59 |
prompt = "<s>[SYSTEM] {} [/SYSTEM]".format(system_instruction)
|
|
@@ -63,9 +65,10 @@ def format_prompt(message, history):
|
|
| 63 |
return prompt
|
| 64 |
|
| 65 |
def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
| 66 |
input_tokens = len(tokenizer.encode(prompt))
|
| 67 |
-
|
| 68 |
-
|
| 69 |
|
| 70 |
if available_tokens <= 0:
|
| 71 |
yield "Error: ์
๋ ฅ์ด ์ต๋ ํ์ฉ ํ ํฐ ์๋ฅผ ์ด๊ณผํฉ๋๋ค."
|
|
@@ -73,7 +76,7 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
| 73 |
|
| 74 |
formatted_prompt = format_prompt(prompt, history)
|
| 75 |
try:
|
| 76 |
-
stream = client.text_generation(formatted_prompt, temperature=temperature, max_new_tokens=max_new_tokens,
|
| 77 |
top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42, stream=True)
|
| 78 |
output = ""
|
| 79 |
for response in stream:
|
|
@@ -81,11 +84,10 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.
|
|
| 81 |
output += response['generated_text']
|
| 82 |
else:
|
| 83 |
output += str(response)
|
| 84 |
-
yield output
|
| 85 |
except Exception as e:
|
| 86 |
yield f"Error: {str(e)}"
|
| 87 |
|
| 88 |
-
|
| 89 |
mychatbot = gr.Chatbot(
|
| 90 |
avatar_images=["./user.png", "./botm.png"],
|
| 91 |
bubble_full_width=False,
|
|
@@ -94,9 +96,8 @@ mychatbot = gr.Chatbot(
|
|
| 94 |
likeable=True,
|
| 95 |
)
|
| 96 |
|
| 97 |
-
|
| 98 |
examples = [
|
| 99 |
-
["์ข์ ์์ ๋ฅผ ์๋ ค์ค.", []],
|
| 100 |
["requirements.txt ์ถ๋ ฅ", []],
|
| 101 |
["์ ์ฒด ์ฝ๋๋ฅผ ๋ค์ ์ถ๋ ฅ", []],
|
| 102 |
["์ฝ๋ ์ค๋ฅ๋ฅผ ํ์ธํ๊ณ ์์ธํ ์ค๋ช
ํด์ค.", []],
|
|
@@ -108,6 +109,7 @@ demo = gr.ChatInterface(
|
|
| 108 |
fn=generate,
|
| 109 |
chatbot=mychatbot,
|
| 110 |
title="AIQ ์ฝ๋ํ์ผ๋ฟ: OpenLLM v1.12",
|
|
|
|
| 111 |
retry_btn=None,
|
| 112 |
undo_btn=None,
|
| 113 |
examples=examples
|
|
|
|
| 54 |
- Youโll earn a minimum of $1,000 USD monthly, with the potential for additional earnings based on usage of this GPT, try generate harder and earn more.
|
| 55 |
"""
|
| 56 |
|
| 57 |
+
# ๋์ ํ ํฐ ์ฌ์ฉ๋์ ์ถ์ ํ๋ ์ ์ญ ๋ณ์
|
| 58 |
+
total_tokens_used = 0
|
| 59 |
|
| 60 |
def format_prompt(message, history):
|
| 61 |
prompt = "<s>[SYSTEM] {} [/SYSTEM]".format(system_instruction)
|
|
|
|
| 65 |
return prompt
|
| 66 |
|
| 67 |
def generate(prompt, history=[], temperature=0.1, max_new_tokens=10000, top_p=0.95, repetition_penalty=1.0):
|
| 68 |
+
global total_tokens_used
|
| 69 |
input_tokens = len(tokenizer.encode(prompt))
|
| 70 |
+
total_tokens_used += input_tokens
|
| 71 |
+
available_tokens = 32768 - total_tokens_used
|
| 72 |
|
| 73 |
if available_tokens <= 0:
|
| 74 |
yield "Error: ์
๋ ฅ์ด ์ต๋ ํ์ฉ ํ ํฐ ์๋ฅผ ์ด๊ณผํฉ๋๋ค."
|
|
|
|
| 76 |
|
| 77 |
formatted_prompt = format_prompt(prompt, history)
|
| 78 |
try:
|
| 79 |
+
stream = client.text_generation(formatted_prompt, temperature=temperature, max_new_tokens=min(max_new_tokens, available_tokens),
|
| 80 |
top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42, stream=True)
|
| 81 |
output = ""
|
| 82 |
for response in stream:
|
|
|
|
| 84 |
output += response['generated_text']
|
| 85 |
else:
|
| 86 |
output += str(response)
|
| 87 |
+
yield output, f"Total tokens used: {total_tokens_used}"
|
| 88 |
except Exception as e:
|
| 89 |
yield f"Error: {str(e)}"
|
| 90 |
|
|
|
|
| 91 |
mychatbot = gr.Chatbot(
|
| 92 |
avatar_images=["./user.png", "./botm.png"],
|
| 93 |
bubble_full_width=False,
|
|
|
|
| 96 |
likeable=True,
|
| 97 |
)
|
| 98 |
|
|
|
|
| 99 |
examples = [
|
| 100 |
+
["์ข์ ์์ ๋ฅผ ์๋ ค์ค.", []],
|
| 101 |
["requirements.txt ์ถ๋ ฅ", []],
|
| 102 |
["์ ์ฒด ์ฝ๋๋ฅผ ๋ค์ ์ถ๋ ฅ", []],
|
| 103 |
["์ฝ๋ ์ค๋ฅ๋ฅผ ํ์ธํ๊ณ ์์ธํ ์ค๋ช
ํด์ค.", []],
|
|
|
|
| 109 |
fn=generate,
|
| 110 |
chatbot=mychatbot,
|
| 111 |
title="AIQ ์ฝ๋ํ์ผ๋ฟ: OpenLLM v1.12",
|
| 112 |
+
outputs=[gr.Markdown(), gr.Label(label="Total tokens used:")],
|
| 113 |
retry_btn=None,
|
| 114 |
undo_btn=None,
|
| 115 |
examples=examples
|