israel789 commited on
Commit
a97c162
verified
1 Parent(s): 5039ccf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -1,26 +1,27 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # 讬爪讬专转 诪讜讚诇 诇谞讬转讜讞 专讙砖讜转
5
- sentiment_analysis = pipeline(
6
- "sentiment-analysis",
7
- model="avichr/heBERT_sentiment_analysis",
8
- tokenizer="avichr/heBERT_sentiment_analysis",
9
- return_all_scores = True
10
- )
11
-
12
- # 驻讜谞拽爪讬讛 诇谞讬转讜讞 讛讟拽住讟
13
- def analyze_sentiment(text):
14
- results = sentiment_analysis(text)[0]
15
- return {r['label']: f"{r['score']:.2%}" for r in results}
 
 
 
16
 
17
- # 讬爪讬专转 讛诪诪砖拽
18
- iface = gr.Interface(
19
- fn=analyze_sentiment,
20
- inputs="text",
21
- outputs="label",
22
- title="谞讬转讜讞 专讙砖讜转 讘注讘专讬转",
23
- description="讛讻谞住 讟拽住讟 讘注讘专讬转 讜拽讘诇 谞讬转讜讞 专讙砖讜转"
24
  )
25
 
26
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
 
4
+ def analyze_text(text):
5
+ try:
6
+ tokenizer = AutoTokenizer.from_pretrained("avichr/heBERT_sentiment_analysis")
7
+ model = AutoModelForSequenceClassification.from_pretrained("avichr/heBERT_sentiment_analysis")
8
+
9
+ classifier = pipeline(
10
+ "sentiment-analysis",
11
+ model=model,
12
+ tokenizer=tokenizer
13
+ )
14
+
15
+ result = classifier(text)
16
+ return str(result)
17
+ except Exception as e:
18
+ return f"Error: {str(e)}"
19
 
20
+ interface = gr.Interface(
21
+ fn=analyze_text,
22
+ inputs=gr.Textbox(label="讛讻谞住 讟拽住讟 讘注讘专讬转"),
23
+ outputs=gr.Textbox(label="转讜爪讗讛"),
24
+ title="谞讬转讜讞 专讙砖讜转 讘注讘专讬转"
 
 
25
  )
26
 
27
+ interface.launch()