crodri commited on
Commit
3c1280f
1 Parent(s): f6547ca

First commit

Browse files

cloned from spaces for testing

Files changed (3) hide show
  1. README.md +30 -1
  2. app.py +56 -0
  3. requirements.txt +7 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: ViquipediaQA
3
  emoji: 🦀
4
  colorFrom: red
5
  colorTo: green
@@ -11,3 +11,32 @@ license: osl-3.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Catalan QA from ViquipediaQA
3
  emoji: 🦀
4
  colorFrom: red
5
  colorTo: green
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
14
+
15
+
16
+ # Configuration
17
+
18
+ `title`: _string_
19
+ Display title for the Space
20
+
21
+ `emoji`: _string_
22
+ Space emoji (emoji-only character allowed)
23
+
24
+ `colorFrom`: _string_
25
+ Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
26
+
27
+ `colorTo`: _string_
28
+ Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
29
+
30
+ `sdk`: _string_
31
+ Can be either `gradio` or `streamlit`
32
+
33
+ `sdk_version` : _string_
34
+ Only applicable for `streamlit` SDK.
35
+ See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
36
+
37
+ `app_file`: _string_
38
+ Path to your main application file (which contains either `gradio` or `streamlit` Python code).
39
+ Path is relative to the root of the repository.
40
+
41
+ `pinned`: _boolean_
42
+ Whether the Space stays on top of your list.
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import wikipedia
3
+ wikipedia.set_lang("ca")
4
+ import random
5
+ import gradio as gr
6
+
7
+ model_name = "projecte-aina/roberta-base-ca-cased-qa"
8
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
9
+
10
+
11
+ def get_wiki_article(topic):
12
+ topic=topic
13
+ try:
14
+ search = wikipedia.search(topic, results = 1)[0]
15
+ except wikipedia.DisambiguationError as e:
16
+ choices = [x for x in e.options if ('disambiguation' not in x) and ('All pages' not in x) and (x!=topic)]
17
+ search = random.choice(choices)
18
+ try:
19
+ p = wikipedia.page(search)
20
+ except wikipedia.exceptions.DisambiguationError as e:
21
+ choices = [x for x in e.options if ('disambiguation' not in x) and ('All pages' not in x) and (x!=topic)]
22
+ s = random.choice(choices)
23
+ p = wikipedia.page(s)
24
+ return p.content, p.url
25
+
26
+ def get_answer(topic, question):
27
+ w_art, w_url=get_wiki_article(topic)
28
+ qa = {'question': question, 'context': w_art}
29
+ res = nlp(qa)
30
+ return res['answer'], w_url, {'confidence':res['score']}
31
+
32
+
33
+ inputs = [
34
+ gr.inputs.Textbox(lines=5, label="Topic"),
35
+ gr.inputs.Textbox(lines=5, label="Question")
36
+ ]
37
+ outputs = [
38
+ gr.outputs.Textbox(type='str',label="Answer"),
39
+ gr.outputs.Textbox(type='str',label="Wikipedia Reference Article"),
40
+ gr.outputs.Label(type="confidences",label="Confidence in answer (assuming the correct wikipedia article)"),
41
+ ]
42
+
43
+ title = "Question Answering with ELECTRA and Wikipedia"
44
+ description = 'Please note that topics with long articles may take around a minute. If you get an error, please try double checking spelling, or try a more specific topic (e.g. George H. Bush instead of George Bush).'
45
+ article = ''
46
+ examples = [
47
+ ['Parma', 'Qui era el duc de Parma?'],
48
+ ['Michelangelo Buonarroti', 'On va morir Miquel Àngel?'],
49
+ ['Antoni Gaudí', "Quina era la professió d'Antoni Gaudí?"],
50
+ ['Arquitectura', "Quina era la professió d'Antoni Gaudí?"],
51
+
52
+
53
+ ]
54
+
55
+ gr.Interface(get_answer, inputs, outputs, title=title, description=description, article=article,
56
+ theme="darkdefault", examples=examples, flagging_options=["strongly related","related", "neutral", "unrelated", "stongly unrelated"]).launch(share=False,enable_queue=False)
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ gradio==2.6.2
2
+ scikit_learn==1.0.2
3
+ scipy==1.6.1
4
+ thefuzz==0.19.0
5
+ torch==1.10.1
6
+ transformers==4.15.0
7
+ wikipedia==1.4.0