samuelrince
commited on
Commit
•
e1dae5e
1
Parent(s):
4d074f8
feat: add basic interface
Browse files
app.py
CHANGED
@@ -1,7 +1,115 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from ecologits.tracers.utils import compute_llm_impacts
|
3 |
|
|
|
|
|
4 |
|
5 |
+
MODELS = [
|
6 |
+
("OpenAI / GPT-3.5-Turbo", "openai/gpt-3.5-turbo"),
|
7 |
+
("OpenAI / GPT-4", "openai/gpt-4"),
|
8 |
+
("Anthropic / Claude 3 Opus", "anthropic/claude-3-opus-20240229"),
|
9 |
+
("Anthropic / Claude 3 Sonnet", "anthropic/claude-3-sonnet-20240229"),
|
10 |
+
("Anthropic / Claude 3 Haiku", "anthropic/claude-3-haiku-20240307"),
|
11 |
+
("Anthropic / Claude 2.1", "anthropic/claude-2.1"),
|
12 |
+
("Anthropic / Claude 2", "anthropic/claude-2"),
|
13 |
+
("Anthropic / Claude Instant 1.2", "anthropic/claude-instant-1.2"),
|
14 |
+
("Mistral AI / Mistral 7B", "mistralai/open-mistral-7b"),
|
15 |
+
("Mistral AI / Mixtral 8x7B", "mistralai/open-mixtral-8x7b"),
|
16 |
+
("Mistral AI / Mixtral 8x22B", "mistralai/open-mixtral-8x22b"),
|
17 |
+
("Mistral AI / Tiny", "mistralai/mistral-tiny-2312"),
|
18 |
+
("Mistral AI / Small", "mistralai/mistral-small-2402"),
|
19 |
+
("Mistral AI / Medium", "mistralai/mistral-medium-2312"),
|
20 |
+
("Mistral AI / Large", "mistralai/mistral-large-2402"),
|
21 |
+
("Meta / Llama 3 8B", "huggingface_hub/meta-llama/Meta-Llama-3-8B"),
|
22 |
+
("Meta / Llama 3 70B", "huggingface_hub/meta-llama/Meta-Llama-3-70B"),
|
23 |
+
("Meta / Llama 2 7B", "huggingface_hub/meta-llama/Llama-2-7b-hf"),
|
24 |
+
("Meta / Llama 2 13B", "huggingface_hub/meta-llama/Llama-2-13b-hf"),
|
25 |
+
("Meta / Llama 2 70B", "huggingface_hub/meta-llama/Llama-2-70b-hf"),
|
26 |
+
("Cohere / Command Light", "cohere/command-light"),
|
27 |
+
("Cohere / Command", "cohere/command"),
|
28 |
+
("Cohere / Command R", "cohere/command-r"),
|
29 |
+
("Cohere / Command R+", "cohere/command-r-plus"),
|
30 |
+
]
|
31 |
+
|
32 |
+
|
33 |
+
PROMPTS = [
|
34 |
+
("Write an email", 170),
|
35 |
+
("Write an article summary", 250),
|
36 |
+
("Write a Tweet", 50),
|
37 |
+
("Write a report of 5 pages", 5000),
|
38 |
+
("Small conversation with a chatbot", 400)
|
39 |
+
]
|
40 |
+
|
41 |
+
|
42 |
+
def format_indicator(name: str, value: str, unit: str) -> str:
|
43 |
+
return f"""
|
44 |
+
## {name}
|
45 |
+
$$ \LARGE {value} \ \small {unit} $$
|
46 |
+
"""
|
47 |
+
|
48 |
+
|
49 |
+
def form(
|
50 |
+
model_name: str,
|
51 |
+
prompt_generated_tokens: int,
|
52 |
+
):
|
53 |
+
provider, model_name = model_name.split('/', 1)
|
54 |
+
impacts = compute_llm_impacts(
|
55 |
+
provider=provider,
|
56 |
+
model_name=model_name,
|
57 |
+
output_token_count=prompt_generated_tokens,
|
58 |
+
request_latency=100000
|
59 |
+
)
|
60 |
+
return (
|
61 |
+
format_indicator("⚡️ Energy", f"{impacts.energy.value:.3f}", impacts.energy.unit),
|
62 |
+
format_indicator("🌍 GHG Emissions", f"{impacts.gwp.value:.3f}", impacts.gwp.unit),
|
63 |
+
format_indicator("🪨 Abiotic Resources", f"{impacts.adpe.value:.3e}", impacts.adpe.unit),
|
64 |
+
format_indicator("⛽️ Primary Energy", f"{round(impacts.pe.value)}", impacts.pe.unit),
|
65 |
+
)
|
66 |
+
|
67 |
+
|
68 |
+
with gr.Blocks() as demo:
|
69 |
+
gr.Markdown("""
|
70 |
+
# 🌱 EcoLogits Calculator
|
71 |
+
|
72 |
+
**EcoLogits** is a python library that tracks the **energy consumption** and **environmental footprint** of using
|
73 |
+
**generative AI** models through APIs.
|
74 |
+
|
75 |
+
⭐️ us on GitHub: [genai-impact/ecologits](https://github.com/genai-impact/ecologits) | Read the documentation:
|
76 |
+
[ecologits.ai](https://ecologits.ai)
|
77 |
+
""")
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
model = gr.Dropdown(
|
81 |
+
MODELS,
|
82 |
+
label="Model name",
|
83 |
+
value="openai/gpt-3.5-turbo",
|
84 |
+
filterable=True,
|
85 |
+
)
|
86 |
+
prompt = gr.Dropdown(
|
87 |
+
PROMPTS,
|
88 |
+
label="Prompt",
|
89 |
+
value=170
|
90 |
+
)
|
91 |
+
|
92 |
+
with gr.Row():
|
93 |
+
energy = gr.Markdown(
|
94 |
+
label="energy",
|
95 |
+
latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
|
96 |
+
)
|
97 |
+
gwp = gr.Markdown(
|
98 |
+
label="gwp",
|
99 |
+
latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
|
100 |
+
)
|
101 |
+
adpe = gr.Markdown(
|
102 |
+
label="adpe",
|
103 |
+
latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
|
104 |
+
)
|
105 |
+
pe = gr.Markdown(
|
106 |
+
label="pe",
|
107 |
+
latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
|
108 |
+
)
|
109 |
+
|
110 |
+
btn = gr.Button("Submit")
|
111 |
+
btn.click(fn=form, inputs=[model, prompt], outputs=[energy, gwp, adpe, pe])
|
112 |
+
|
113 |
+
|
114 |
+
if __name__ == '__main__':
|
115 |
+
demo.launch()
|