GoshawkVortexAI commited on
Commit
949ea0b
·
verified ·
1 Parent(s): 3db58ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -33
app.py CHANGED
@@ -1,39 +1,14 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
- import torch
4
 
5
- # Model ve Tokenizer'ı yükleme
6
- MODEL_NAME = "GoshawkVortexAI/Goshawk_Finbert" # Goshawk FinBERT modelini kullanacağız
7
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_auth_token=True)
8
- model = AutoModelForSequenceClassification.from_pretrained(MODEL_NAME, use_auth_token=True)
9
 
10
- # Sentiment analizi fonksiyonu
11
  def analyze_sentiment(text):
12
- # Verilen metni tokenize et
13
- inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
14
 
15
- # CPU'da çalışacak şekilde modelin inference yapmasını sağlıyoruz
16
- with torch.no_grad():
17
- outputs = model(**inputs)
18
-
19
- # Modelin çıktısını al (logits)
20
- logits = outputs.logits
21
- predicted_class = torch.argmax(logits, dim=-1).item()
22
-
23
- # Sentiment sınıfını belirle
24
- if predicted_class == 0:
25
- return "Negative"
26
- elif predicted_class == 1:
27
- return "Neutral"
28
- else:
29
- return "Positive"
30
 
31
- # Gradio arayüzü
32
- iface = gr.Interface(fn=analyze_sentiment,
33
- inputs="text",
34
- outputs="text",
35
- title="Financial Sentiment Analysis",
36
- description="Enter a financial text, and the model will analyze its sentiment (Positive, Neutral, or Negative).")
37
-
38
- # Uygulamayı başlat
39
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # DistilBERT modelini yükle
5
+ model = pipeline("sentiment-analysis", model="distilbert-base-uncased")
 
 
6
 
 
7
  def analyze_sentiment(text):
8
+ return model(text)
 
9
 
10
+ # Gradio arayüzünü oluştur
11
+ iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="json")
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ # CPU üzerinde çalışacak şekilde başlat
14
+ iface.launch(share=False)