hassamniaz7 commited on
Commit
5987a9f
·
verified ·
1 Parent(s): e33ced9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -3
app.py CHANGED
@@ -1,4 +1,31 @@
1
- import time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from transformers import AutoTokenizer, pipeline
3
  from optimum.onnxruntime import ORTModelForSequenceClassification
4
  import gradio as gr
@@ -6,6 +33,12 @@ import gradio as gr
6
 
7
  # with gr.Blocks(css=css) as demo:# box1 = gr.Textbox(value="Good Job", elem_classes="feedback")# box2 = gr.Textbox(value="Failure", elem_id="warning", elem_classes="feedback")
8
  model_id = "HassamAliCADI/SentimentOnx"
 
 
 
 
 
 
9
 
10
  model = ORTModelForSequenceClassification.from_pretrained(model_id)
11
  tokenizer = AutoTokenizer.from_pretrained(model_id)
@@ -15,9 +48,9 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
15
  pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
16
 
17
  def classify_text(text):
18
- start_time = time.time()
19
  results = pipe(text)
20
- end_time = time.time()
21
 
22
  # with gr.Blocks(css=".gradio-container {background-color: red}") as demo:# with gr.Blocks(css=".gradio-container {background: url('file=clouds.jpg')}") as demo:# css = """
23
 
 
1
+ import os
2
+ import subprocess
3
+
4
+ def install_packages():
5
+ packages = [
6
+ "torch",
7
+ "transformers",
8
+ "huggingface-hub",
9
+ "gradio",
10
+ "accelerate",
11
+ "onnxruntime",
12
+ "onnxruntime-tools",
13
+ "optimum",
14
+ ]
15
+ for package in packages:
16
+ result = subprocess.run(f'pip install {package}', shell=True)
17
+ if result.returncode != 0:
18
+ print(f"Failed to install {package}")
19
+ else:
20
+ print(f"Successfully installed {package}")
21
+
22
+ install_packages()
23
+
24
+ import gradio as gr
25
+ from huggingface_hub import login
26
+ from optimum.onnxruntime import ORTModelForSeq2SeqLM
27
+ from transformers import AutoTokenizer, pipeline
28
+
29
  from transformers import AutoTokenizer, pipeline
30
  from optimum.onnxruntime import ORTModelForSequenceClassification
31
  import gradio as gr
 
33
 
34
  # with gr.Blocks(css=css) as demo:# box1 = gr.Textbox(value="Good Job", elem_classes="feedback")# box2 = gr.Textbox(value="Failure", elem_id="warning", elem_classes="feedback")
35
  model_id = "HassamAliCADI/SentimentOnx"
36
+ hf_token = os.environ.get("NLP")
37
+
38
+ if hf_token:
39
+ login(hf_token)
40
+ else:
41
+ print("NLP token not found.")
42
 
43
  model = ORTModelForSequenceClassification.from_pretrained(model_id)
44
  tokenizer = AutoTokenizer.from_pretrained(model_id)
 
48
  pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
49
 
50
  def classify_text(text):
51
+ # start_time = time.time()
52
  results = pipe(text)
53
+ # end_time = time.time()
54
 
55
  # with gr.Blocks(css=".gradio-container {background-color: red}") as demo:# with gr.Blocks(css=".gradio-container {background: url('file=clouds.jpg')}") as demo:# css = """
56