alishabhale commited on
Commit
04fe564
·
1 Parent(s): e29c41b

updated the code

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -1,26 +1,36 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
3
  import torch
4
 
5
- # Load Model & Tokenizer
6
  model_name = "meta-llama/Llama-2-7b-chat-hf"
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
  model = AutoModelForCausalLM.from_pretrained(
9
  model_name, torch_dtype=torch.float16, device_map="auto"
10
  )
 
11
 
12
- # Function to generate responses
13
- def chat_with_llama(input_text):
14
- inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
15
- output = model.generate(**inputs, max_new_tokens=200)
16
- return tokenizer.decode(output[0], skip_special_tokens=True)
 
 
 
 
 
 
 
17
 
18
- # Gradio UI
19
  iface = gr.Interface(
20
- fn=chat_with_llama,
21
- inputs="text",
22
  outputs="text",
23
- title="Llama-2 Chatbot"
 
24
  )
25
 
26
  iface.launch()
 
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
 
14
+ # Function to analyze CSV data
15
+ def analyze_csv(file):
16
+ df = pd.read_csv(file.name) # Read uploaded CSV
17
+ benchmark_text = df.to_string() # Convert DataFrame to text
18
+
19
+ prompt = f"Analyze the following benchmark scores and recommend the best model:\n\n{benchmark_text}"
20
+
21
+ # Generate response using Llama-2
22
+ output = pipe(prompt, max_length=500, do_sample=True, temperature=0.7)
23
+ analysis_result = output[0]['generated_text']
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()