Kim Adams commited on
Commit
65b1935
·
1 Parent(s): 168653b

adding translator frame

Browse files
app.py CHANGED
@@ -1,40 +1,20 @@
1
  import gradio as gr
2
- import openai, config, os
3
- import requests, base64
4
- import pandas as pd
5
- import numpy as np
6
  from huggingface_hub import Repository
7
  from io import BytesIO
8
  from dotenv import load_dotenv
9
  from openai.embeddings_utils import get_embedding, cosine_similarity
 
 
10
 
11
- def get_openai_api_key():
12
- openai_api_key = os.environ.get('OPENAI_API_KEY')
 
13
 
14
- if openai_api_key is None:
15
- load_dotenv()
16
- openai_api_key = os.environ['OPENAI_API_KEY']
 
17
 
18
- return openai_api_key
19
-
20
- openai.api_key = get_openai_api_key()
21
-
22
- def get_eleven_api_key_and_voice_id():
23
- eleven_api_key = os.environ.get('ELEVEN_LABS_API_KEY')
24
- voice_id = os.environ.get('VOICE_ID')
25
-
26
- if eleven_api_key is None:
27
- load_dotenv()
28
- eleven_api_key = os.environ['ELEVEN_LABS_API_KEY']
29
- voice_id = os.environ['VOICE_ID']
30
-
31
- return eleven_api_key, voice_id
32
-
33
- eleven_api_key, voice_id = get_eleven_api_key_and_voice_id()
34
-
35
-
36
- def greet(name):
37
- return "Hello " + name + "!!"
38
-
39
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
40
  iface.launch()
 
1
  import gradio as gr
2
+ import openai, os
 
 
 
3
  from huggingface_hub import Repository
4
  from io import BytesIO
5
  from dotenv import load_dotenv
6
  from openai.embeddings_utils import get_embedding, cosine_similarity
7
+ from ml_to_nl_translation.translation import greet
8
+ from utilities import api_keys
9
 
10
+ openai.api_key = api_keys.APIKeys().get_key('OPENAI_API_KEY')
11
+ eleven_api_key = api_keys.APIKeys().get_key('ELEVEN_LABS_API_KEY')
12
+ voice_id = api_keys.APIKeys().get_key('VOICE_ID')
13
 
14
+ def translator_wrapper(name):
15
+ result=greet(name, openai.api_key)
16
+ print(result)
17
+ return result
18
 
19
+ iface = gr.Interface(fn=translator_wrapper, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  iface.launch()
ml-to-nl-translation/translation.py DELETED
File without changes
ml_to_nl_translation/__pycache__/translation.cpython-311.pyc ADDED
Binary file (1.18 kB). View file
 
{ml-to-nl-translation → ml_to_nl_translation}/data/temperature_sensor_data.json RENAMED
File without changes
ml_to_nl_translation/translation.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import pandas as pd
3
+ import numpy as np
4
+ import openai, os, tiktoken, json
5
+ import importlib.util
6
+ from openai.embeddings_utils import cosine_similarity, get_embedding
7
+ from sklearn.metrics import classification_report, PrecisionRecallDisplay
8
+ from collections import Counter
9
+ from nltk.corpus import wordnet
10
+ from nltk.tokenize import word_tokenize
11
+
12
+
13
+ def greet(name, key):
14
+ response = "Hello " + name + "!! openAI key found: " + str(key is not None)
15
+ print("response from greet:" + response)
16
+ return response
utilities/__pycache__/api_keys.cpython-311.pyc ADDED
Binary file (991 Bytes). View file
 
utilities/api_keys.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+
4
+ class APIKeys:
5
+ def __init__(self):
6
+ load_dotenv()
7
+
8
+ def get_key(self, key_name):
9
+ key = os.getenv(key_name)
10
+ if key:
11
+ return key
12
+ else:
13
+ print(f'No value found for {key_name}')
14
+ return None
15
+