ihsan66 commited on
Commit
f2bf1fd
1 Parent(s): a315ad2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -43
app.py CHANGED
@@ -60,6 +60,38 @@ model_dict = {
60
 
61
  pipeline_model = load_pipeline(model_dict[task], task)
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  if st.button("Çalıştır") and input_text:
64
  if task in ["Metin Sınıflandırma", "Duygu Analizi"]:
65
  output = pipeline_model(input_text)
@@ -69,42 +101,9 @@ if st.button("Çalıştır") and input_text:
69
  elif task == "Metin Analizi":
70
  output = pipeline_model(input_text)
71
 
72
- # Varlıkları birleştirmek için işlev
73
- def process_entities(entities, text):
74
- result = []
75
- current_entity = None
76
- for entity in entities:
77
- if entity['entity'].startswith('I-'):
78
- if current_entity and current_entity['Label'] == entity['entity']:
79
- current_entity['Word'] += entity['word']
80
- current_entity['End'] = entity['end']
81
- current_entity['Score'] = max(current_entity['Score'], entity['score'])
82
- else:
83
- if current_entity:
84
- result.append(current_entity)
85
- current_entity = {
86
- 'Label': entity['entity'],
87
- 'Score': entity['score'],
88
- 'Word': entity['word'],
89
- 'Start': entity['start'],
90
- 'End': entity['end']
91
- }
92
- else:
93
- if current_entity:
94
- result.append(current_entity)
95
- current_entity = {
96
- 'Label': entity['entity'],
97
- 'Score': entity['score'],
98
- 'Word': entity['word'],
99
- 'Start': entity['start'],
100
- 'End': entity['end']
101
- }
102
- if current_entity:
103
- result.append(current_entity)
104
- return result
105
-
106
- entities = process_entities(output, input_text)
107
- df = pd.DataFrame(entities)
108
  st.subheader("Tanımlanan Varlıklar")
109
  st.dataframe(df)
110
 
@@ -113,11 +112,11 @@ if st.button("Çalıştır") and input_text:
113
  formatted_text = ""
114
  last_end = 0
115
  for item in text_data:
116
- if item['Start'] > last_end:
117
- formatted_text += original_text[last_end:item['Start']]
118
- word = item['Word']
119
- label = item['Label']
120
- score = item['Score']
121
  if label.startswith('I-PER'):
122
  color = 'blue'
123
  elif label.startswith('I-MISC'):
@@ -125,12 +124,12 @@ if st.button("Çalıştır") and input_text:
125
  else:
126
  color = 'gray'
127
  formatted_text += f"<span style='color:{color}; font-weight: bold;'>{word} ({label}, {score:.2f})</span>"
128
- last_end = item['End']
129
  if last_end < len(original_text):
130
  formatted_text += original_text[last_end:]
131
  return formatted_text
132
 
133
- formatted_text = format_text(entities, input_text)
134
  st.subheader("Analiz Edilen Metin")
135
  st.markdown(f"<p>{formatted_text}</p>", unsafe_allow_html=True)
136
  elif task == "Metin Oluşturma":
 
60
 
61
  pipeline_model = load_pipeline(model_dict[task], task)
62
 
63
+ def process_entities(entities, text):
64
+ """
65
+ Varlıkları birleştirip anlamlı bir şekilde düzenler.
66
+ """
67
+ processed_entities = []
68
+ current_entity = None
69
+
70
+ for entity in entities:
71
+ if entity['entity'].startswith('I-'):
72
+ if current_entity and current_entity['label'] == entity['entity']:
73
+ current_entity['word'] += entity['word'].replace('##', '')
74
+ current_entity['end'] = entity['end']
75
+ current_entity['score'] = max(current_entity['score'], entity['score'])
76
+ else:
77
+ if current_entity:
78
+ processed_entities.append(current_entity)
79
+ current_entity = {
80
+ 'label': entity['entity'],
81
+ 'word': entity['word'].replace('##', ''),
82
+ 'start': entity['start'],
83
+ 'end': entity['end'],
84
+ 'score': entity['score']
85
+ }
86
+ else:
87
+ if current_entity:
88
+ processed_entities.append(current_entity)
89
+ current_entity = None
90
+ if current_entity:
91
+ processed_entities.append(current_entity)
92
+
93
+ return processed_entities
94
+
95
  if st.button("Çalıştır") and input_text:
96
  if task in ["Metin Sınıflandırma", "Duygu Analizi"]:
97
  output = pipeline_model(input_text)
 
101
  elif task == "Metin Analizi":
102
  output = pipeline_model(input_text)
103
 
104
+ # Process entities
105
+ processed_entities = process_entities(output, input_text)
106
+ df = pd.DataFrame(processed_entities)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  st.subheader("Tanımlanan Varlıklar")
108
  st.dataframe(df)
109
 
 
112
  formatted_text = ""
113
  last_end = 0
114
  for item in text_data:
115
+ if item['start'] > last_end:
116
+ formatted_text += original_text[last_end:item['start']]
117
+ word = item['word']
118
+ label = item['label']
119
+ score = item['score']
120
  if label.startswith('I-PER'):
121
  color = 'blue'
122
  elif label.startswith('I-MISC'):
 
124
  else:
125
  color = 'gray'
126
  formatted_text += f"<span style='color:{color}; font-weight: bold;'>{word} ({label}, {score:.2f})</span>"
127
+ last_end = item['end']
128
  if last_end < len(original_text):
129
  formatted_text += original_text[last_end:]
130
  return formatted_text
131
 
132
+ formatted_text = format_text(processed_entities, input_text)
133
  st.subheader("Analiz Edilen Metin")
134
  st.markdown(f"<p>{formatted_text}</p>", unsafe_allow_html=True)
135
  elif task == "Metin Oluşturma":