Mary12 commited on
Commit
64c0a70
·
1 Parent(s): 4bfe1f4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForQuestionAnswering
3
+ import torch
4
+ import transformers
5
+ from transformers import pipeline
6
+
7
+ def model(model_name):
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name,return_dict = False)
10
+ model_pipeline = pipeline(
11
+ "question-answering",
12
+ model = model,
13
+ tokenizer = tokenizer
14
+ )
15
+
16
+ return model_pipeline
17
+
18
+ def qa_result(context, question):
19
+ model_name = "timpal0l/mdeberta-v3-base-squad2"
20
+ pipe = model(model_name)
21
+ result = pipe(question = question, context=context)
22
+ answered = result['answer']
23
+
24
+ return answered
25
+
26
+ theme = gr.themes.Soft().set(
27
+ body_background_fill='*background_fill_secondary',
28
+ body_text_color_subdued='*body_text_color',
29
+ body_text_color_subdued_dark='*chatbot_code_background_color'
30
+ )
31
+
32
+ app = gr.Interface(fn=qa_result,
33
+ inputs = ['textbox', 'text'],
34
+ outputs = 'textbox', title = 'Ողջու՛յն։ Ես քո արհեստական բանականությամբ օգնականն եմ ', theme = theme, description = 'Տու՛ր ինձ տեքստ, ու տեքստին վերաբերող հարցեր, ու ես կօգնեմ քեզ պատասխանել հարցերին')
35
+
36
+
37
+ app.launch(inline=False)