ihsan66 commited on
Commit
a315ad2
1 Parent(s): 0bf758f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -11
app.py CHANGED
@@ -69,32 +69,38 @@ if st.button("Çalıştır") and input_text:
69
  elif task == "Metin Analizi":
70
  output = pipeline_model(input_text)
71
 
72
- # Varlıkları ayırmak ve birleştirmek
73
  def process_entities(entities, text):
74
- # Varlıkları birleştirmek için bir yapı oluştur
75
  result = []
 
76
  for entity in entities:
77
  if entity['entity'].startswith('I-'):
78
- if result and result[-1]['Label'] == entity['entity']:
79
- result[-1]['Word'] += entity['word']
80
- result[-1]['End'] = entity['end']
81
- result[-1]['Score'] = max(result[-1]['Score'], entity['score'])
82
  else:
83
- result.append({
 
 
84
  'Label': entity['entity'],
85
  'Score': entity['score'],
86
  'Word': entity['word'],
87
  'Start': entity['start'],
88
  'End': entity['end']
89
- })
90
  else:
91
- result.append({
 
 
92
  'Label': entity['entity'],
93
  'Score': entity['score'],
94
  'Word': entity['word'],
95
  'Start': entity['start'],
96
  'End': entity['end']
97
- })
 
 
98
  return result
99
 
100
  entities = process_entities(output, input_text)
@@ -118,4 +124,16 @@ if st.button("Çalıştır") and input_text:
118
  color = 'green'
119
  else:
120
  color = 'gray'
121
-
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
 
124
  color = 'green'
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":
137
+ output = pipeline_model(input_text, max_length=100, num_return_sequences=1)
138
+ st.subheader("Oluşturulan Metin")
139
+ st.write(output[0]['generated_text'])