merve HF staff commited on
Commit
e2ba245
1 Parent(s): 24e7f2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -10
app.py CHANGED
@@ -10,6 +10,46 @@ import os
10
  from deta import Deta
11
 
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  openai.api_key = os.getenv('API_KEY')
14
  reader = Reader(["tr"])
15
 
@@ -83,16 +123,8 @@ def openai_response(ocr_input):
83
  Output:
84
  """
85
 
86
- response = openai.Completion.create(
87
- model="text-davinci-003",
88
- prompt=prompt,
89
- temperature=0,
90
- max_tokens=300,
91
- top_p=1,
92
- frequency_penalty=0.0,
93
- presence_penalty=0.0,
94
- stop=["\n"],
95
- )
96
  resp = response["choices"][0]["text"]
97
  print(resp)
98
  resp = eval(resp.replace("'{", "{").replace("}'", "}"))
 
10
  from deta import Deta
11
 
12
 
13
+ ######################
14
+ import requests
15
+ from rest_framework import status
16
+ from concurrent.futures import Future, ThreadPoolExecutor, as_completed
17
+ import json
18
+
19
+ import os
20
+ import openai
21
+
22
+
23
+
24
+ class OpenAI_API:
25
+ def __init__(self):
26
+ self.openai_api_key = ''
27
+
28
+ def single_request(self, address_text):
29
+
30
+ openai.api_type = "azure"
31
+ openai.api_base = "https://damlaopenai.openai.azure.com/"
32
+ openai.api_version = "2022-12-01"
33
+ openai.api_key = os.getenv("API_KEY")
34
+
35
+ response = openai.Completion.create(
36
+ engine="Davinci-003",
37
+ prompt=prompt,
38
+ temperature=0.9,
39
+ max_tokens=256,
40
+ top_p=1.0,
41
+ n=1,
42
+ logprobs=0,
43
+ echo=False,
44
+ stop=None,
45
+ frequency_penalty=0,
46
+ presence_penalty=0,
47
+ best_of=1)
48
+
49
+ return response
50
+
51
+ ########################
52
+
53
  openai.api_key = os.getenv('API_KEY')
54
  reader = Reader(["tr"])
55
 
 
123
  Output:
124
  """
125
 
126
+ openai_client = OpenAI_API()
127
+ response = openai_client.single_request(ocr_input)
 
 
 
 
 
 
 
 
128
  resp = response["choices"][0]["text"]
129
  print(resp)
130
  resp = eval(resp.replace("'{", "{").replace("}'", "}"))