Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,21 @@
|
|
| 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") #
|
| 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=
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(
|
| 16 |
-
model_name, torch_dtype=torch.float16, device_map="auto", use_auth_token=
|
| 17 |
)
|
| 18 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 19 |
|
| 20 |
-
# Function to analyze CSV data
|
| 21 |
def analyze_csv(file):
|
| 22 |
df = pd.read_csv(file.name) # Read uploaded CSV
|
| 23 |
benchmark_text = df.to_string() # Convert DataFrame to text
|
|
@@ -30,7 +28,7 @@ def analyze_csv(file):
|
|
| 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"),
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import torch
|
| 6 |
|
| 7 |
+
# ✅ Get Hugging Face token securely from Space Secrets
|
| 8 |
+
HUGGINGFACE_TOKEN = os.getenv("HF_TOKEN") # Make sure you set this in HF Secrets!
|
|
|
|
| 9 |
|
| 10 |
+
# ✅ Load Llama-2 Model & Tokenizer (without login())
|
| 11 |
model_name = "meta-llama/Llama-2-7b-chat-hf"
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HUGGINGFACE_TOKEN)
|
| 13 |
model = AutoModelForCausalLM.from_pretrained(
|
| 14 |
+
model_name, torch_dtype=torch.float16, device_map="auto", use_auth_token=HUGGINGFACE_TOKEN
|
| 15 |
)
|
| 16 |
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 17 |
|
| 18 |
+
# ✅ Function to analyze CSV data
|
| 19 |
def analyze_csv(file):
|
| 20 |
df = pd.read_csv(file.name) # Read uploaded CSV
|
| 21 |
benchmark_text = df.to_string() # Convert DataFrame to text
|
|
|
|
| 28 |
|
| 29 |
return analysis_result # Return the analysis
|
| 30 |
|
| 31 |
+
# ✅ Gradio Interface
|
| 32 |
iface = gr.Interface(
|
| 33 |
fn=analyze_csv,
|
| 34 |
inputs=gr.File(label="Upload CSV File"),
|