Update app.py
Browse files
app.py
CHANGED
@@ -87,13 +87,12 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=25000, top_p=0.
|
|
87 |
input_tokens = len(tokenizer.encode(prompt))
|
88 |
available_tokens = 32768 - input_tokens
|
89 |
max_new_tokens = min(max_new_tokens, available_tokens)
|
90 |
-
|
91 |
if available_tokens <= 0:
|
92 |
-
yield "Error: ์
๋ ฅ์ด ์ต๋ ํ์ฉ ํ ํฐ ์๋ฅผ ์ด๊ณผํฉ๋๋ค."
|
93 |
return
|
94 |
|
95 |
formatted_prompt = format_prompt(prompt, history)
|
96 |
-
|
97 |
try:
|
98 |
stream = client.text_generation(formatted_prompt, temperature=temperature, max_new_tokens=max_new_tokens,
|
99 |
top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42, stream=True)
|
@@ -102,10 +101,11 @@ def generate(prompt, history=[], temperature=0.1, max_new_tokens=25000, top_p=0.
|
|
102 |
if isinstance(response, dict) and 'generated_text' in response:
|
103 |
output += response['generated_text']
|
104 |
else:
|
105 |
-
output += str(response)
|
106 |
-
|
107 |
except Exception as e:
|
108 |
-
yield f"Error: {str(e)}
|
|
|
109 |
|
110 |
|
111 |
mychatbot = gr.Chatbot(
|
@@ -125,14 +125,18 @@ examples = [
|
|
125 |
["Huggingface์ Gradio๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๋ฌผ์ด๋ณด์ธ์.", []]
|
126 |
]
|
127 |
|
|
|
|
|
|
|
128 |
|
129 |
-
demo = gr.
|
130 |
fn=generate,
|
131 |
-
|
|
|
|
|
132 |
title="AIQ ์ฝ๋ํ์ผ๋ฟ: OpenLLM v1.12",
|
133 |
-
|
134 |
-
|
135 |
-
examples=examples
|
136 |
)
|
137 |
|
138 |
-
demo.
|
|
|
87 |
input_tokens = len(tokenizer.encode(prompt))
|
88 |
available_tokens = 32768 - input_tokens
|
89 |
max_new_tokens = min(max_new_tokens, available_tokens)
|
90 |
+
|
91 |
if available_tokens <= 0:
|
92 |
+
yield "Error: ์
๋ ฅ์ด ์ต๋ ํ์ฉ ํ ํฐ ์๋ฅผ ์ด๊ณผํฉ๋๋ค.", input_tokens
|
93 |
return
|
94 |
|
95 |
formatted_prompt = format_prompt(prompt, history)
|
|
|
96 |
try:
|
97 |
stream = client.text_generation(formatted_prompt, temperature=temperature, max_new_tokens=max_new_tokens,
|
98 |
top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42, stream=True)
|
|
|
101 |
if isinstance(response, dict) and 'generated_text' in response:
|
102 |
output += response['generated_text']
|
103 |
else:
|
104 |
+
output += str(response)
|
105 |
+
yield output, input_tokens + max_new_tokens
|
106 |
except Exception as e:
|
107 |
+
yield f"Error: {str(e)}", 0
|
108 |
+
|
109 |
|
110 |
|
111 |
mychatbot = gr.Chatbot(
|
|
|
125 |
["Huggingface์ Gradio๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๋ฌผ์ด๋ณด์ธ์.", []]
|
126 |
]
|
127 |
|
128 |
+
def update_output(result):
|
129 |
+
output_text, used_tokens = result
|
130 |
+
return output_text, f"Used tokens: {used_tokens}"
|
131 |
|
132 |
+
demo = gr.Interface(
|
133 |
fn=generate,
|
134 |
+
inputs=[gr.Textbox(label="์ง๋ฌธ์ ์
๋ ฅํ์ธ์", placeholder="์ฌ๊ธฐ์ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์...", lines=2), gr.JSON(label="History", value=[])],
|
135 |
+
outputs=[gr.Markdown(), gr.Label()],
|
136 |
+
examples=examples,
|
137 |
title="AIQ ์ฝ๋ํ์ผ๋ฟ: OpenLLM v1.12",
|
138 |
+
description="AIQ Codepilot๊ณผ ์ํธ์์ฉํด ๋ณด์ธ์.",
|
139 |
+
post_process=update_output # ์ฌ์ฉ๋ ํ ํฐ ์ ์
๋ฐ์ดํธ๋ฅผ ์ํ ํฌ์คํธ ํ๋ก์ธ์ค ํจ์
|
|
|
140 |
)
|
141 |
|
142 |
+
demo.launch(show_api=False)
|