BioMike commited on
Commit
c32b8eb
·
verified ·
1 Parent(s): 44bf001

Delete interfaces/classification.py

Browse files
Files changed (1) hide show
  1. interfaces/classification.py +0 -119
interfaces/classification.py DELETED
@@ -1,119 +0,0 @@
1
- from gliner import GLiNER
2
- import gradio as gr
3
-
4
- model = GLiNER.from_pretrained("knowledgator/gliner-multitask-v1.0").to("cpu")
5
-
6
- PROMPT_TEMPLATE = """Classify the given text having the following classes: {}"""
7
- classification_examples = [
8
- [
9
- """
10
- "I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
11
-
12
- The headphones themselves are remarkable. The noise-canceling feature works like a charm in the bustling city environment, and the 30-hour battery life means I don't have to charge them every day. Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.
13
-
14
- I also appreciated the customer service from Amazon when I had a question about the warranty. They responded within an hour and provided all the information I needed.
15
-
16
- However, the headphones did not come with a hard case, which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.
17
-
18
- Overall, I'd give these headphones a 4.5/5 rating and highly recommend them to anyone looking for top-notch quality in both product and service.""",
19
- "positive review, negative review, neutral review",
20
- 0.5
21
- ],
22
- [
23
- "I really enjoyed the pizza we had for dinner last night.",
24
- "Food, Weather, Sports",
25
- 0.5
26
- ],
27
- [
28
- "Das Kind spielt im Park und genießt die frische Luft.",
29
- "Nature, Technology, Politics",
30
- 0.5
31
- ],
32
- [
33
- """
34
- "Last night, we visited the new Italian restaurant downtown. The Margherita pizza was absolutely delightful, with a perfectly crisp crust and fresh basil.
35
-
36
- However, the service was slow; it took over 20 minutes to take our order. The pasta arrived lukewarm, which was disappointing given the hype around this place.
37
-
38
- On the bright side, the ambiance was cozy, and the wine selection was impressive. Overall, it was a mixed experience, but I might give it another try on a quieter evening."
39
- """,
40
- "Food Quality, Technology, Politics",
41
- 0.5
42
- ],
43
- [
44
- """
45
- "Das Kind verbrachte den Nachmittag im Park und entdeckte einen kleinen Teich mit Enten. Es war wunderschön zu sehen, wie es die Natur erkundete.
46
-
47
- Doch plötzlich störten die Geräusche einer Baustelle die ruhige Atmosphäre. Trotzdem spielte das Kind weiter, und ich genoss die frische Luft.
48
-
49
- Solche Momente zeigen, wie wichtig es ist, Kinder in der Natur aufwachsen zu lassen."
50
- """,
51
- "Outdoor Activities, Gaming, Artificial Intelligence",
52
- 0.5
53
- ],
54
- [
55
- """
56
- "I recently attended a healthcare technology conference. The keynote speaker demonstrated how AI is revolutionizing diagnostics, making it possible to detect rare diseases with incredible accuracy.
57
-
58
- However, concerns about data privacy and ethical implications were also heavily discussed. Despite these challenges, the energy in the room was palpable as experts envisioned a future where AI saves millions of lives.
59
-
60
- It was an inspiring event that showcased the potential of combining technology and healthcare innovation."
61
- """,
62
- "Artificial Intelligence, Music, Sports",
63
- 0.5
64
- ]
65
- ]
66
-
67
- def prepare_prompts(text, labels):
68
- labels_str = ', '.join(labels)
69
- return PROMPT_TEMPLATE.format(labels_str) + "\n" + text
70
-
71
- def process(text, labels, threshold):
72
- if not text.strip() or not labels.strip():
73
- return {"text": text, "entities": []}
74
-
75
- labels = [label.strip() for label in labels.split(",")]
76
- prompt = prepare_prompts(text, labels)
77
-
78
- predictions = model.run([prompt], ["match"], threshold=threshold)
79
- entities = []
80
-
81
- if predictions and predictions[0]:
82
- for pred in predictions[0]:
83
- entities.append({
84
- "entity": "match",
85
- "word": pred["text"],
86
- "start": pred["start"],
87
- "end": pred["end"],
88
- "score": pred["score"]
89
- })
90
-
91
- return {"text": prompt, "entities": entities}
92
-
93
- with gr.Blocks(title="Text Classification with Highlighted Labels") as classification_interface:
94
- gr.Markdown("# Text Classification with Highlighted Labels")
95
-
96
- input_text = gr.Textbox(label="Input Text", placeholder="Enter text for classification")
97
- input_labels = gr.Textbox(label="Labels (Comma-Separated)", placeholder="Enter labels separated by commas (e.g., Positive, Negative, Neutral)")
98
- threshold = gr.Slider(0, 1, value=0.5, step=0.01, label="Threshold")
99
-
100
- output = gr.HighlightedText(label="Classification Results")
101
-
102
- submit_btn = gr.Button("Classify")
103
-
104
- examples = gr.Examples(
105
- examples=classification_examples,
106
- inputs=[input_text, input_labels, threshold],
107
- outputs=output,
108
- fn=process,
109
- cache_examples=True
110
- )
111
- theme=gr.themes.Base()
112
-
113
-
114
- input_text.submit(fn=process, inputs=[input_text, input_labels, threshold], outputs=output)
115
- threshold.release(fn=process, inputs=[input_text, input_labels, threshold], outputs=output)
116
- submit_btn.click(fn=process, inputs=[input_text, input_labels, threshold], outputs=output)
117
-
118
- if __name__ == "__main__":
119
- classification_interface.launch()