ihsan66 commited on
Commit
f3452ba
1 Parent(s): 8db6403

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -17
app.py CHANGED
@@ -60,7 +60,7 @@ model_dict = {
60
 
61
  pipeline_model = load_pipeline(model_dict[task], task)
62
 
63
- def process_entities(entities):
64
  """
65
  Varlıkları birleştirip anlamlı bir şekilde düzenler.
66
  """
@@ -68,7 +68,7 @@ def process_entities(entities):
68
  current_entity = None
69
 
70
  for entity in entities:
71
- if 'entity' in entity and 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']
@@ -104,22 +104,21 @@ if st.button("Çalıştır") and input_text:
104
  # Process entities
105
  processed_entities = []
106
  for entity in output:
107
- if 'entity' in entity:
108
- word = entity.get('word', '')
109
- label = entity.get('entity', '')
110
- score = entity.get('score', 0.0)
111
- start = entity.get('start', 0)
112
- end = entity.get('end', 0)
113
- processed_entities.append({
114
- 'word': word,
115
- 'label': label,
116
- 'score': score,
117
- 'start': start,
118
- 'end': end
119
- })
120
 
121
  # Aggregate entities
122
- df = pd.DataFrame(process_entities(processed_entities))
123
  st.subheader("Tanımlanan Varlıklar")
124
  st.dataframe(df)
125
 
@@ -129,4 +128,26 @@ if st.button("Çalıştır") and input_text:
129
  last_end = 0
130
  for item in text_data:
131
  if item['start'] > last_end:
132
- formatted_text += original_text[
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  """
 
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']
 
104
  # Process entities
105
  processed_entities = []
106
  for entity in output:
107
+ word = entity['word']
108
+ label = entity['entity']
109
+ score = entity['score']
110
+ start = entity['start']
111
+ end = entity['end']
112
+ processed_entities.append({
113
+ 'word': word,
114
+ 'label': label,
115
+ 'score': score,
116
+ 'start': start,
117
+ 'end': end
118
+ })
 
119
 
120
  # Aggregate entities
121
+ df = pd.DataFrame(process_entities(processed_entities, input_text))
122
  st.subheader("Tanımlanan Varlıklar")
123
  st.dataframe(df)
124
 
 
128
  last_end = 0
129
  for item in text_data:
130
  if item['start'] > last_end:
131
+ formatted_text += original_text[last_end:item['start']]
132
+ word = item['word']
133
+ label = item['label']
134
+ score = item['score']
135
+ if label.startswith('I-PER'):
136
+ color = 'blue'
137
+ elif label.startswith('I-MISC'):
138
+ color = 'green'
139
+ else:
140
+ color = 'gray'
141
+ formatted_text += f"<span style='color:{color}; font-weight: bold;'>{word} ({label}, {score:.2f})</span>"
142
+ last_end = item['end']
143
+ if last_end < len(original_text):
144
+ formatted_text += original_text[last_end:]
145
+ return formatted_text
146
+
147
+ formatted_text = format_text(process_entities(processed_entities, input_text), input_text)
148
+ st.subheader("Analiz Edilen Metin")
149
+ st.markdown(f"<p>{formatted_text}</p>", unsafe_allow_html=True)
150
+ elif task == "Metin Oluşturma":
151
+ output = pipeline_model(input_text, max_length=100, num_return_sequences=1)
152
+ st.subheader("Oluşturulan Metin")
153
+ st.write(output[0]['generated_text'])