Spaces:
Runtime error
Runtime error
Edited OAI model params, created few-shot template, separated deta.sh flow
Browse files- app.py +20 -6
- openai_api.py +8 -8
app.py
CHANGED
@@ -27,11 +27,12 @@ def get_parsed_address(input_img):
|
|
27 |
return openai_response(address_full_text)
|
28 |
|
29 |
|
|
|
|
|
|
|
30 |
# Open API on change
|
31 |
def text_dict(input):
|
32 |
eval_result = ast.literal_eval(input)
|
33 |
-
utils.write_db(eval_result)
|
34 |
-
|
35 |
return (
|
36 |
str(eval_result["city"]),
|
37 |
str(eval_result["distinct"]),
|
@@ -50,9 +51,20 @@ def openai_response(ocr_input):
|
|
50 |
of arbitrary size, but the output should be in [{{'tabular': {{'entity_type': 'entity'}} }}] JSON format Force it
|
51 |
to only extract keys that are shared as an example in the examples section, if a key value is not found in the
|
52 |
text input, then it should be ignored. Have only city, distinct, neighbourhood,
|
53 |
-
street, no, tel, name_surname, address Examples:
|
54 |
-
|
|
|
55 |
Output: {{'city': 'İstanbul', 'distinct': 'Beşiktaş', 'neighbourhood': 'Yıldız Mahallesi', 'street': 'Cumhuriyet Caddesi', 'no': '35', 'tel': '5551231256', 'name_surname': 'Ahmet Yılmaz', 'address': 'İstanbul, Beşiktaş, Yıldız Mahallesi, Cumhuriyet Caddesi No: 35'}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
Input: {ocr_input}
|
57 |
Output:
|
58 |
"""
|
@@ -94,7 +106,7 @@ with gr.Blocks() as demo:
|
|
94 |
img_area = gr.Image(label="Ekran Görüntüsü yükleyin 👇")
|
95 |
ocr_result = gr.Textbox(label="Metin yükleyin 👇 ")
|
96 |
open_api_text = gr.Textbox(label="Tam Adres")
|
97 |
-
run_button = gr.Button(value="
|
98 |
with gr.Column():
|
99 |
with gr.Row():
|
100 |
city = gr.Textbox(label="İl", interactive=True)
|
@@ -126,7 +138,9 @@ with gr.Blocks() as demo:
|
|
126 |
open_api_text,
|
127 |
[city, distinct, neighbourhood, street, address, tel, name_surname, no],
|
128 |
)
|
129 |
-
|
|
|
|
|
130 |
|
131 |
if __name__ == "__main__":
|
132 |
demo.launch()
|
|
|
27 |
return openai_response(address_full_text)
|
28 |
|
29 |
|
30 |
+
def save_deta_db(input):
|
31 |
+
eval_result = ast.literal_eval(input)
|
32 |
+
utils.write_db(eval_result)
|
33 |
# Open API on change
|
34 |
def text_dict(input):
|
35 |
eval_result = ast.literal_eval(input)
|
|
|
|
|
36 |
return (
|
37 |
str(eval_result["city"]),
|
38 |
str(eval_result["distinct"]),
|
|
|
51 |
of arbitrary size, but the output should be in [{{'tabular': {{'entity_type': 'entity'}} }}] JSON format Force it
|
52 |
to only extract keys that are shared as an example in the examples section, if a key value is not found in the
|
53 |
text input, then it should be ignored. Have only city, distinct, neighbourhood,
|
54 |
+
street, no, tel, name_surname, address Examples:
|
55 |
+
|
56 |
+
Input: Deprem sırasında evimizde yer alan adresimiz: İstanbul, Beşiktaş, Yıldız Mahallesi, Cumhuriyet Caddesi No: 35, cep telefonu numaram 5551231256, adim Ahmet Yilmaz
|
57 |
Output: {{'city': 'İstanbul', 'distinct': 'Beşiktaş', 'neighbourhood': 'Yıldız Mahallesi', 'street': 'Cumhuriyet Caddesi', 'no': '35', 'tel': '5551231256', 'name_surname': 'Ahmet Yılmaz', 'address': 'İstanbul, Beşiktaş, Yıldız Mahallesi, Cumhuriyet Caddesi No: 35'}}
|
58 |
+
|
59 |
+
Input: 5.29 PMO $ 0 87 DEVREMİZ ÖZGÜR ORÇAN ARKADAŞIMIZA ULAŞAMIYORUZ BEYOĞLU MAH FEVZİ ÇAKMAK CAD. NO.58-TÜRKOĞLUI KAHRAMANMARAŞ 5524357578 AdReSe YaKIN OLANLAR VEYA ULASANLAR LÜTFEN BiLGILENDIRSIN .
|
60 |
+
Output: {{'city': 'Kahramanmaraş', 'distinct': 'Türkoğlu', 'neighbourhood': 'Beyoğlu Mahallesi', 'street': 'Çakmak Caddesi', 'no': '58', 'tel': '5524357578', 'name_surname': 'Özgür Orçan', 'address': 'Beyoğlu Mahallesi, Çakmak Caddesi, No:58 Türkoğlu/Kahramanmaraş'}}
|
61 |
+
|
62 |
+
Input: Ahmet @ozknhmt Ekim 2021 tarihinde katıldı - 2 Takipçi Takip ettiğin kimse takip etmiyor AKEVLER MAH. 432SK RÜYA APT ANT(BEDİİ SABUNCU KARŞISI) ANTAKYA HATAY MERVE BELANLI ses veriyor ancak hiçbiryardım ekibi olmadığı için kurtaramryoruz içeri girip, lütfen acil yardım_ İsim: Merve Belanlı tel 542 757 5484 Ö0 12.07
|
63 |
+
Output: {{'city': 'Hatay', 'distinct': 'Antakya', 'neighbourhood': 'Akevler Mahallesi', 'street': '432 Sokak', 'no': '', 'tel': '5427575484', 'name_surname': 'Merve Belanlı', 'address': 'Akevler Mahallesi, 432 Sokak, Rüya Apt. Antakya/Hatay'}}
|
64 |
+
|
65 |
+
Input: 14:04 Sümerler Cemil Şükrü Çolokoğlu ilköğretim okulu karşısı 3 9öçük altında yardım bekyouk Lütfen herkes paylogsın
|
66 |
+
Output: {{'city': '', 'distinct': '', 'neighbourhood': 'Sümerler Mahallesi', 'street': 'Cemil Şükrü Çolokoğlu İlköğretim Okulu Karşısı', 'no': '', 'tel': '', 'name_surname': '', 'address': 'Sümerler Mahallesi, Cemil Şükrü Çolokoğlu İlköğretim Okulu Karşısı'}}
|
67 |
+
|
68 |
Input: {ocr_input}
|
69 |
Output:
|
70 |
"""
|
|
|
106 |
img_area = gr.Image(label="Ekran Görüntüsü yükleyin 👇")
|
107 |
ocr_result = gr.Textbox(label="Metin yükleyin 👇 ")
|
108 |
open_api_text = gr.Textbox(label="Tam Adres")
|
109 |
+
run_button = gr.Button(value="Veriyi İşle", label="Yükle")
|
110 |
with gr.Column():
|
111 |
with gr.Row():
|
112 |
city = gr.Textbox(label="İl", interactive=True)
|
|
|
138 |
open_api_text,
|
139 |
[city, distinct, neighbourhood, street, address, tel, name_surname, no],
|
140 |
)
|
141 |
+
|
142 |
+
submit_button = gr.Button(value="Veriyi Birimlere Yolla")
|
143 |
+
submit_button.click(save_deta_db, open_api_text)
|
144 |
|
145 |
if __name__ == "__main__":
|
146 |
demo.launch()
|
openai_api.py
CHANGED
@@ -15,16 +15,16 @@ class OpenAI_API:
|
|
15 |
response = openai.Completion.create(
|
16 |
engine="Davinci-003",
|
17 |
prompt=address_text,
|
18 |
-
temperature=0
|
19 |
-
max_tokens=
|
20 |
-
top_p=1
|
21 |
-
n=1,
|
22 |
-
logprobs=0,
|
23 |
-
echo=False,
|
24 |
-
stop=
|
25 |
frequency_penalty=0,
|
26 |
presence_penalty=0,
|
27 |
-
best_of=1,
|
28 |
)
|
29 |
|
30 |
return response
|
|
|
15 |
response = openai.Completion.create(
|
16 |
engine="Davinci-003",
|
17 |
prompt=address_text,
|
18 |
+
temperature=0.,
|
19 |
+
max_tokens=500,
|
20 |
+
top_p=1,
|
21 |
+
# n=1,
|
22 |
+
# logprobs=0,
|
23 |
+
# echo=False,
|
24 |
+
stop=["\n"],
|
25 |
frequency_penalty=0,
|
26 |
presence_penalty=0,
|
27 |
+
# best_of=1,
|
28 |
)
|
29 |
|
30 |
return response
|