dwb2023 commited on
Commit
c1fc3a9
1 Parent(s): fe656cd

Update app.py

Browse files

initial commit

Files changed (1) hide show
  1. app.py +31 -27
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
  import os
3
- import torch, torchvision, einops
4
- import spaces
5
  from transformers import AutoModelForCausalLM
6
  from huggingface_hub import login
7
- import subprocess
8
 
 
9
  subprocess.run(
10
  "pip install flash-attn --no-build-isolation",
11
  env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
@@ -15,34 +15,38 @@ subprocess.run(
15
  hf_token = os.getenv("HF_TOKEN")
16
  login(token=hf_token, add_to_git_credential=True)
17
 
 
18
  @spaces.GPU
19
  def get_model_summary(model_name):
20
- # Check if CUDA is available and set the device accordingly
21
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
22
-
23
- # Load the model and move it to the selected device
24
  model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).to(device)
25
-
26
- # Return the model's architecture as a string
27
  return str(model)
28
 
29
- # Create the Gradio interface
30
- interface = gr.Interface(
31
- fn=get_model_summary,
32
- inputs="text",
33
- examples=[
34
- ["google/gemma-7b"],
35
- ["microsoft/Phi-3-mini-4k-instruct"],
36
- ["meta-llama/Meta-Llama-3-8B"],
37
- ["mistralai/Mistral-7B-Instruct-v0.3"],
38
- ["vikhyatk/moondream2"],
39
- ["microsoft/Phi-3-vision-128k-instruct"],
40
- ["openbmb/MiniCPM-Llama3-V-2_5"],
41
- ["google/paligemma-3b-mix-224"],
42
- ["HuggingFaceM4/idefics2-8b-chatty"],
43
- ["mistralai/Codestral-22B-v0.1"]
44
- ],
45
- outputs="text"
46
- )
 
 
 
 
 
 
 
47
 
48
- interface.launch()
 
 
1
  import gradio as gr
2
  import os
3
+ import torch
4
+ import subprocess
5
  from transformers import AutoModelForCausalLM
6
  from huggingface_hub import login
 
7
 
8
+ # Install required package
9
  subprocess.run(
10
  "pip install flash-attn --no-build-isolation",
11
  env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
 
15
  hf_token = os.getenv("HF_TOKEN")
16
  login(token=hf_token, add_to_git_credential=True)
17
 
18
+ # Function to get the model summary
19
  @spaces.GPU
20
  def get_model_summary(model_name):
 
21
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
 
22
  model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).to(device)
 
 
23
  return str(model)
24
 
25
+ # Create the Gradio Blocks interface
26
+ with gr.Blocks() as demo:
27
+ with gr.Row():
28
+ with gr.Column():
29
+ textbox = gr.Textbox(label="Model Name")
30
+ examples = gr.Examples(
31
+ examples=[
32
+ ["google/gemma-7b"],
33
+ ["microsoft/Phi-3-mini-4k-instruct"],
34
+ ["meta-llama/Meta-Llama-3-8B"],
35
+ ["mistralai/Mistral-7B-Instruct-v0.3"],
36
+ ["vikhyatk/moondream2"],
37
+ ["microsoft/Phi-3-vision-128k-instruct"],
38
+ ["openbmb/MiniCPM-Llama3-V-2_5"],
39
+ ["google/paligemma-3b-mix-224"],
40
+ ["HuggingFaceM4/idefics2-8b-chatty"],
41
+ ["mistralai/Codestral-22B-v0.1"]
42
+ ],
43
+ inputs=textbox
44
+ )
45
+ submit_button = gr.Button("Submit")
46
+ with gr.Column():
47
+ output = gr.Textbox(label="Output", lines=20)
48
+
49
+ submit_button.click(fn=get_model_summary, inputs=textbox, outputs=output)
50
 
51
+ # Launch the interface
52
+ demo.launch()