Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
|
|
|
| 4 |
|
| 5 |
-
MODEL_URL = "
|
| 6 |
-
WEBSITE_URL = "https://www.kodiks.com/ai_solutions.html"
|
| 7 |
|
| 8 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def prediction(news):
|
| 12 |
# create pipeline
|
| 13 |
-
clasifer = pipeline("
|
| 14 |
-
|
| 15 |
-
preds = clasifer(news)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
preds_dict[pred['label']] = pred['score']
|
| 20 |
|
| 21 |
-
return
|
| 22 |
|
| 23 |
|
| 24 |
gradio_ui = gr.Interface(
|
| 25 |
fn=prediction,
|
| 26 |
-
title="
|
| 27 |
-
description=f"
|
| 28 |
examples=[
|
| 29 |
-
['
|
| 30 |
-
["
|
| 31 |
-
["
|
| 32 |
-
["Kamu bankaları Halkbank, Vakıfbank ve Ziraat Bankası ortak bir açıklama yayınlayarak kredi faiz oranlarında indirim yapıldığını açıkladı. Söz konusu indirimler ticari ve konut kredileri kapsıyor. Tüketici kredisi kapsam dışında bırakıldı."]
|
| 33 |
],
|
| 34 |
-
inputs=gr.inputs.Textbox(lines=10, label="
|
| 35 |
-
outputs=gr.outputs.Label(num_top_classes=5, type="auto", label="
|
| 36 |
theme="huggingface",
|
| 37 |
-
article="<p style='text-align: center'>
|
| 38 |
)
|
| 39 |
|
| 40 |
gradio_ui.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
MODEL_URL = "kingabzpro/Llama-3.1-8B-Instruct-Mental-Health-Classification"
|
|
|
|
| 7 |
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_URL)
|
| 9 |
+
|
| 10 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_URL, low_cpu_mem_usage=True, return_dict=True,torch_dtype=torch.float16,
|
| 11 |
+
device_map="cpu")
|
| 12 |
|
| 13 |
def prediction(news):
|
| 14 |
# create pipeline
|
| 15 |
+
clasifer = pipeline("text-generation", tokenizer=tokenizer, model=model, torch_dtype=torch.float16,
|
| 16 |
+
device_map="cpu",)
|
|
|
|
| 17 |
|
| 18 |
+
outputs = pipe(prompt, max_new_tokens=2, do_sample=True, temperature=0.1)
|
| 19 |
+
preds = outputs[0]["generated_text"].split("label: ")[-1].strip())
|
|
|
|
| 20 |
|
| 21 |
+
return preds
|
| 22 |
|
| 23 |
|
| 24 |
gradio_ui = gr.Interface(
|
| 25 |
fn=prediction,
|
| 26 |
+
title="Mental Health Disorder Classification",
|
| 27 |
+
description=f"Input the text to generate a Mental Health Disorder.\n For this classification, the {MODEL_URL} model was used.",
|
| 28 |
examples=[
|
| 29 |
+
['trouble sleeping, confused mind, restless heart. All out of tune'],
|
| 30 |
+
["In the quiet hours, even the shadows seem too heavy to bear."],
|
| 31 |
+
["Riding a tempest of emotions, where ecstatic highs crash into desolate lows without warning."]
|
|
|
|
| 32 |
],
|
| 33 |
+
inputs=gr.inputs.Textbox(lines=10, label="Write the text here"),
|
| 34 |
+
outputs=gr.outputs.Label(num_top_classes=5, type="auto", label="Mental Health Disorder Category"),
|
| 35 |
theme="huggingface",
|
| 36 |
+
article="<p style='text-align: center'>Please read the tutorial to fine-tune the Llama 3.1 model on Mental Health Classification <a href='https://www.datacamp.com/tutorial/fine-tuning-llama-3-1' target='_blank'>https://www.datacamp.com/tutorial/fine-tuning-llama-3-1</a></p>",
|
| 37 |
)
|
| 38 |
|
| 39 |
gradio_ui.launch()
|