Spaces:
Runtime error
Runtime error
BusinessDev
commited on
Commit
•
b3e3f8a
1
Parent(s):
5d11984
gradio
Browse files
app.py
CHANGED
@@ -1,29 +1,6 @@
|
|
1 |
from transformers import MBartForConditionalGeneration, MBart50Tokenizer
|
2 |
import dat
|
3 |
-
import
|
4 |
-
import platform
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def setvar():
|
9 |
-
if platform.system() == "Windows":
|
10 |
-
print("Windows detected. Assigning cache directory to Transformers in AppData \ Local.")
|
11 |
-
transformers_cache_directory = os.path.join(os.getenv('LOCALAPPDATA'), 'transformers_cache')
|
12 |
-
if not os.path.exists(transformers_cache_directory):
|
13 |
-
try:
|
14 |
-
os.mkdir(transformers_cache_directory)
|
15 |
-
print(f"First launch. Directory '{transformers_cache_directory}' created successfully.")
|
16 |
-
except OSError as e:
|
17 |
-
print(f"Error creating directory '{transformers_cache_directory}': {e}")
|
18 |
-
else:
|
19 |
-
print(f"Directory '{transformers_cache_directory}' already exists.")
|
20 |
-
os.environ['TRANSFORMERS_CACHE'] = transformers_cache_directory
|
21 |
-
print("Environment variable assigned.")
|
22 |
-
del transformers_cache_directory
|
23 |
-
|
24 |
-
else:
|
25 |
-
print("Windows not detected. Assignment of Transformers cache directory not necessary.")
|
26 |
-
|
27 |
|
28 |
# Load the model and tokenizer
|
29 |
model_name = "LocalDoc/mbart_large_qa_azerbaijan"
|
@@ -52,9 +29,11 @@ def answer_question(context, question):
|
|
52 |
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
53 |
return answer
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
58 |
|
59 |
-
|
60 |
-
print(answer)
|
|
|
1 |
from transformers import MBartForConditionalGeneration, MBart50Tokenizer
|
2 |
import dat
|
3 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Load the model and tokenizer
|
6 |
model_name = "LocalDoc/mbart_large_qa_azerbaijan"
|
|
|
29 |
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
30 |
return answer
|
31 |
|
32 |
+
demo = gr.Interface(
|
33 |
+
fn = answer_question,
|
34 |
+
inputs = ['context', 'question'],
|
35 |
+
outputs = ['text']
|
36 |
+
)
|
37 |
+
|
38 |
|
39 |
+
demo.launch()
|
|