File size: 2,315 Bytes
173f590
d9b5faa
173f590
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8413b4b
 
173f590
8413b4b
173f590
 
 
35b78a9
173f590
 
 
 
acf1aea
 
173f590
 
 
8413b4b
 
173f590
 
8413b4b
173f590
 
 
35b78a9
173f590
 
 
 
acf1aea
 
173f590
 
 
 
 
 
 
 
 
 
35b78a9
173f590
 
 
 
acf1aea
 
173f590
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import requests
import httpx


API_TOKEN = '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'
headers = {"Authorization": f"Bearer {API_TOKEN}"}


def query(filename, lang):
    """
    Function to get inference for three languages
    
    """
      
    if (lang == 'ha') and (filename is not None):
        API_URL = "https://api-inference.huggingface.co/models/Tiamz/hausa-4-ha-wa2vec-data-aug-xls-r-300m"
        with open(filename, "rb") as f:
            data = f.read()
        try:
            response = requests.request("POST", API_URL, headers=headers, data=data)
            command = json.loads(response.content.decode("utf-8"))
            command = command['text']
            if command != '':
                #print(command)
                return command
            else:
                print('No response yet')
        except KeyError as e:
            pass
            #return 'Model is still loading..., please wait!'
 
    elif (lang == 'yo') and (filename is not None):
        API_URL = "https://api-inference.huggingface.co/models/Ayoola/cdial-yoruba-test"
        with open(filename, "rb") as f:
            data = f.read()
        
        try:
            response = requests.request("POST", API_URL, headers=headers, data=data)
            command = json.loads(response.content.decode("utf-8"))
            command = command['text']
            if command != '':
                #print(command)
                return command
            else:
                pass
        except KeyError as e:
            pass
            #return 'Model is still loading..., please wait!'
    
    elif (lang == 'en') and (filename is not None):
        API_URL = "https://api-inference.huggingface.co/models/facebook/wav2vec2-base-960h"
        with open(filename, "rb") as f:
            data = f.read()
        try:
            response = httpx.request("POST", API_URL, headers=headers, data=data)
            command = json.loads(response.content.decode("utf-8"))
            command = command['text']
            if command != '':
                #print(command)
                return command.lower()
            else:
                print('No response yet')
        except KeyError as e:
            pass
            #print('Model is still loading..., please wait!'
    else:
        pass