alishabhale commited on
Commit
1b29932
·
verified ·
1 Parent(s): 8b4724f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,13 +1,19 @@
 
 
 
1
  import gradio as gr
2
  import pandas as pd
3
- from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
  import torch
5
 
 
 
 
 
6
  # Load Llama-2 Model & Tokenizer
7
  model_name = "meta-llama/Llama-2-7b-chat-hf"
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
  model = AutoModelForCausalLM.from_pretrained(
10
- model_name, torch_dtype=torch.float16, device_map="auto"
11
  )
12
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
13
 
@@ -24,13 +30,12 @@ def analyze_csv(file):
24
 
25
  return analysis_result # Return the analysis
26
 
27
- # Gradio Interface for CSV Upload and Analysis
28
  iface = gr.Interface(
29
  fn=analyze_csv,
30
  inputs=gr.File(label="Upload CSV File"),
31
  outputs="text",
32
- title="Llama-2 CSV Benchmark Analyzer",
33
- description="Upload a CSV file with benchmark scores, and Llama-2 will analyze and recommend the best model."
34
  )
35
 
36
  iface.launch()
 
1
+ import os
2
+ from huggingface_hub import login
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
  import gradio as gr
5
  import pandas as pd
 
6
  import torch
7
 
8
+ # Get Hugging Face token securely
9
+ HUGGINGFACE_TOKEN = os.getenv("HF_TOKEN") # ✅ Fetch from environment variable
10
+ login(HUGGINGFACE_TOKEN)
11
+
12
  # Load Llama-2 Model & Tokenizer
13
  model_name = "meta-llama/Llama-2-7b-chat-hf"
14
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
15
  model = AutoModelForCausalLM.from_pretrained(
16
+ model_name, torch_dtype=torch.float16, device_map="auto", use_auth_token=True
17
  )
18
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
19
 
 
30
 
31
  return analysis_result # Return the analysis
32
 
33
+ # Gradio Interface
34
  iface = gr.Interface(
35
  fn=analyze_csv,
36
  inputs=gr.File(label="Upload CSV File"),
37
  outputs="text",
38
+ title="Llama-2 CSV Benchmark Analyzer"
 
39
  )
40
 
41
  iface.launch()