ihsan66 commited on
Commit
b236025
1 Parent(s): 32f8762

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -45
app.py CHANGED
@@ -101,52 +101,59 @@ if st.button("Çalıştır") and input_text:
101
  elif task == "Metin Analizi":
102
  output = pipeline_model(input_text)
103
 
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
-
125
- # Metni formatla
126
- def format_text(text_data, original_text):
127
- formatted_text = ""
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")
 
101
  elif task == "Metin Analizi":
102
  output = pipeline_model(input_text)
103
 
104
+ # Çıktıyı gözlemleme
105
+ st.write(output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
+ # Varlıkları işlemek için uygun formatı kontrol edin
108
+ if len(output) > 0 and 'entity' in output[0]:
109
+ # Process entities
110
+ processed_entities = []
111
+ for entity in output:
112
+ word = entity['word']
113
+ label = entity['entity']
114
+ score = entity['score']
115
+ start = entity['start']
116
+ end = entity['end']
117
+ processed_entities.append({
118
+ 'word': word,
119
+ 'label': label,
120
+ 'score': score,
121
+ 'start': start,
122
+ 'end': end
123
+ })
124
+
125
+ # Aggregate entities
126
+ df = pd.DataFrame(process_entities(processed_entities, input_text))
127
+ st.subheader("Tanımlanan Varlıklar")
128
+ st.dataframe(df)
129
+
130
+ # Metni formatla
131
+ def format_text(text_data, original_text):
132
+ formatted_text = ""
133
+ last_end = 0
134
+ for item in text_data:
135
+ if item['start'] > last_end:
136
+ formatted_text += original_text[last_end:item['start']]
137
+ word = item['word']
138
+ label = item['label']
139
+ score = item['score']
140
+ if label.startswith('I-PER'):
141
+ color = 'blue'
142
+ elif label.startswith('I-MISC'):
143
+ color = 'green'
144
+ else:
145
+ color = 'gray'
146
+ formatted_text += f"<span style='color:{color}; font-weight: bold;'>{word} ({label}, {score:.2f})</span>"
147
+ last_end = item['end']
148
+ if last_end < len(original_text):
149
+ formatted_text += original_text[last_end:]
150
+ return formatted_text
151
+
152
+ formatted_text = format_text(process_entities(processed_entities, input_text), input_text)
153
+ st.subheader("Analiz Edilen Metin")
154
+ st.markdown(f"<p>{formatted_text}</p>", unsafe_allow_html=True)
155
+ else:
156
+ st.error("Varlık analizi sonucu beklenen formatta değil.")
157
  elif task == "Metin Oluşturma":
158
  output = pipeline_model(input_text, max_length=100, num_return_sequences=1)
159
  st.subheader("Oluşturulan Metin")