Spaces:
Sleeping
Sleeping
Create base interface
Browse files
app.py
CHANGED
@@ -1,9 +1,36 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
hello_world = gr.Interface(lambda name: "Hello " + name, "text", "text")
|
4 |
-
bye_world = gr.Interface(lambda name: "Bye " + name, "text", "text")
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
if __name__ == "__main__":
|
9 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from tokencost import count_message_tokens, count_string_tokens, calculate_prompt_cost, calculate_completion_cost
|
3 |
|
|
|
|
|
4 |
|
5 |
+
def compute_all(prompt_string, completion_string, model):
|
6 |
+
prompt_cost = calculate_prompt_cost(prompt_string, model)
|
7 |
+
completion_cost = calculate_completion_cost(completion_string, model)
|
8 |
+
|
9 |
+
prompt_tokens = count_string_tokens(prompt_string, model)
|
10 |
+
completion_tokens = count_string_tokens(completion_string, model)
|
11 |
+
|
12 |
+
return prompt_tokens, prompt_cost, completion_tokens, completion_cost
|
13 |
+
|
14 |
+
|
15 |
+
with gr.Blocks(theme='soft') as demo:
|
16 |
+
with gr.Row():
|
17 |
+
with gr.Column():
|
18 |
+
prompt = gr.Textbox(value="Hello world")
|
19 |
+
completion = gr.Textbox(value="...")
|
20 |
+
|
21 |
+
model = gr.Dropdown(value="gpt-3.5-turbo", choices=["gpt-3.5-turbo", "gpt-3.5-turbo"])
|
22 |
+
|
23 |
+
button = gr.Button("Compute costs!")
|
24 |
+
|
25 |
+
with gr.Column():
|
26 |
+
with gr.Row():
|
27 |
+
prompt_tokens = gr.Textbox(interactive=False)
|
28 |
+
prompt_cost = gr.Textbox(interactive=False)
|
29 |
+
with gr.Row():
|
30 |
+
completion_tokens = gr.Textbox(interactive=False)
|
31 |
+
completion_cost = gr.Textbox(interactive=False)
|
32 |
+
|
33 |
+
button.click(compute_all, inputs=[prompt, completion, model], outputs=[prompt_tokens, prompt_cost, completion_tokens, completion_cost])
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
demo.launch()
|