dhmeltzer commited on
Commit
85c676c
1 Parent(s): 15e28e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -53
app.py CHANGED
@@ -3,68 +3,65 @@ import requests
3
  import streamlit as st
4
  import openai
5
 
6
- #def main():
7
- st.title("Scientific Question Generation")
8
-
9
- checkpoints = ['dhmeltzer/bart-large_askscience-qg',
10
- 'dhmeltzer/flan-t5-base_askscience-qg',
11
- 'google/flan-t5-xxl']
12
-
13
- headers = {"Authorization": f"Bearer {st.secrets['HF_token']}"}
14
- openai.api_key = st.secrets['OpenAI_token']
15
-
16
- def query(checkpoint, payload):
17
- API_URL = f"https://api-inference.huggingface.co/models/{checkpoint}"
18
 
19
- response = requests.post(API_URL,
20
- headers=headers,
21
- json=payload)
22
 
23
- return response.json()
24
-
25
- # User search
26
- user_input = st.text_area("Question Generator",
27
- """Black holes are the most gravitationally dense objects in the universe.""")
28
-
29
- if user_input:
30
- for checkpoint in checkpoints:
31
 
32
- model_name = checkpoint.split('/')[1]
33
-
34
- if 'flan' in model_name.lower():
35
-
36
- prompt = 'generate a question: ' + user_input
37
 
38
- output = query(checkpoint,{
39
- "inputs": prompt,
40
- "wait_for_model":True})[0]['generated_text']
41
- else:
 
 
 
 
 
 
 
 
 
 
42
 
43
- prompt = user_input
 
 
 
 
 
 
44
 
45
- output = query(checkpoint,{
46
- "inputs": prompt,
47
- "wait_for_model":True})[0]['generated_text']
 
48
 
49
- st.write(f'Model {model_name}: {output}')
50
-
51
- model_engine = "gpt-3.5-turbo"
52
- max_tokens = 50
53
 
54
- prompt = f"generate a question: {user_input}"
55
-
56
- response=openai.ChatCompletion.create(
57
- model=model_engine,
58
- messages=[
59
- {"role": "system", "content": "You are a helpful assistant that generates questions from text."},
60
- {"role": "user", "content": prompt},
61
- ])
62
-
63
- output = response['choices'][0]['message']['content']
64
 
65
- st.write(f'Model {model_engine}: {output}')
 
 
66
 
67
 
68
- #if __name__ == "__main__":
69
- # main()
70
  #[0]['generated_text']
 
3
  import streamlit as st
4
  import openai
5
 
6
+ def main():
7
+ st.title("Scientific Question Generation")
 
 
 
 
 
 
 
 
 
 
8
 
9
+ checkpoints = ['dhmeltzer/bart-large_askscience-qg',
10
+ 'dhmeltzer/flan-t5-base_askscience-qg',
11
+ 'google/flan-t5-xxl']
12
 
13
+ headers = {"Authorization": f"Bearer {st.secrets['HF_token']}"}
14
+ openai.api_key = st.secrets['OpenAI_token']
15
+
16
+ def query(checkpoint, payload):
17
+ API_URL = f"https://api-inference.huggingface.co/models/{checkpoint}"
 
 
 
18
 
19
+ response = requests.post(API_URL,
20
+ headers=headers,
21
+ json=payload)
 
 
22
 
23
+ return response.json()
24
+
25
+ # User search
26
+ user_input = st.text_area("Question Generator",
27
+ """Black holes are the most gravitationally dense objects in the universe.""")
28
+
29
+ if user_input:
30
+ for checkpoint in checkpoints:
31
+
32
+ model_name = checkpoint.split('/')[1]
33
+
34
+ if 'flan' in model_name.lower():
35
+
36
+ prompt = 'generate a question: ' + user_input
37
 
38
+ try:
39
+ output = query(checkpoint,{
40
+ "inputs": prompt,
41
+ "wait_for_model":True})[0]['generated_text']
42
+ except:
43
+ st.write(output)
44
+ return
45
 
46
+ st.write(f'Model {model_name}: {output}')
47
+
48
+ model_engine = "gpt-3.5-turbo"
49
+ max_tokens = 50
50
 
51
+ prompt = f"generate a question: {user_input}"
 
 
 
52
 
53
+ response=openai.ChatCompletion.create(
54
+ model=model_engine,
55
+ messages=[
56
+ {"role": "system", "content": "You are a helpful assistant that generates questions from text."},
57
+ {"role": "user", "content": prompt},
58
+ ])
 
 
 
 
59
 
60
+ output = response['choices'][0]['message']['content']
61
+
62
+ st.write(f'Model {model_engine}: {output}')
63
 
64
 
65
+ if __name__ == "__main__":
66
+ main()
67
  #[0]['generated_text']