Kaengbold commited on
Commit
43e70c6
·
1 Parent(s): 46f03dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -8
app.py CHANGED
@@ -8,9 +8,10 @@ from sumy.summarizers.lsa import LsaSummarizer as Summarizer
8
  from sumy.nlp.stemmers import Stemmer
9
  from sumy.utils import get_stop_words
10
  import gradio as gr
 
11
 
12
 
13
- def greet(api_key, name):
14
 
15
  def cut_in_half(Text):
16
  list= Text.split('.')
@@ -101,16 +102,59 @@ def greet(api_key, name):
101
  Text = Text + str(sentence)
102
 
103
  return Text
 
 
 
 
 
 
 
 
 
 
 
 
104
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
- Text = name
107
- detail = 1
108
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  if detail != 1:
110
  Text = summerizer(Text, detail)
111
 
112
  Text, x = study_notes(Text)
113
- catorgizer = 2
114
 
115
  while x != -1:
116
  response1 = flashcards_maker(Text,x)
@@ -126,9 +170,28 @@ def greet(api_key, name):
126
 
127
  listsummery = str(listsummery).replace('\n '," \n")
128
  out = f"{listsummery}"
129
- return out
 
 
 
 
130
 
 
 
 
 
 
131
 
 
 
 
 
 
 
 
 
 
 
132
 
133
- iface = gr.Interface(fn=greet, inputs=["text","text"], outputs="text")
134
- iface.launch()
 
8
  from sumy.nlp.stemmers import Stemmer
9
  from sumy.utils import get_stop_words
10
  import gradio as gr
11
+ import csv
12
 
13
 
14
+ def maker(api_key, mode, input_text,detail,Spend_input_data_API_key_is_not_safed):
15
 
16
  def cut_in_half(Text):
17
  list= Text.split('.')
 
102
  Text = Text + str(sentence)
103
 
104
  return Text
105
+ def concept_card_maker(api_key, input_text,detail,Spend_input_data_API_key_is_not_safed):
106
+ concept_name =input_text
107
+ openai.api_key = api_key
108
+ response = openai.Completion.create(
109
+ model="text-davinci-003",
110
+ prompt="Describe \""+ concept_name + "\" as a concept with the point: name, concepts under it(listed in a list split by a comma), which are the bigger topics above it(listed in a list split by a comma), explanation, formula with a variable explanation if existed, use case, example.\n\nName:",
111
+ temperature=0.7,
112
+ max_tokens=800,
113
+ top_p=1,
114
+ frequency_penalty=0,
115
+ presence_penalty=0
116
+ )
117
 
118
+ response = str(response["choices"][0]["text"])
119
+ response = (response).replace("Formula (if existed): N/A\n\n", "")
120
+ response = (response).replace("Formula (if existed): N/A\n", "")
121
+ response = (response).replace("Formula: N/A\n", "")
122
+ response = (response).replace("\n\n", "#\t\t")
123
+ response = (response).replace("\n-", ";\t\t-")
124
+ response = (response).replace("\n", "#\t\t")
125
+ response = (response).replace(";", "\n")
126
+ response = (response).replace("#", "\n\n")
127
+
128
+ return concept_name + "\tConcept"+"\n\t\tName:" +response
129
 
130
+ Text = input_text
131
+ if detail == "No summersiation":
132
+ detail = 1
133
+ elif detail == "low summersation":
134
+ detail = 2
135
+ elif detail == "medium summersation":
136
+ detail = 6
137
+ elif detail == "high summersation":
138
+ detail = 12
139
+
140
+ if mode == "flashcards with topics":
141
+ catorgizer = 1
142
+ if mode == "flashcards":
143
+ catorgizer = 0
144
+ if mode == "concepts cards":
145
+ with open('\concept_data.csv', 'a', newline='') as csvfile:
146
+ out = concept_card_maker(api_key, input_text,detail,Spend_input_data_API_key_is_not_safed)
147
+ if Spend_input_data_API_key_is_not_safed == True:
148
+ writer = csv.writer(csvfile)
149
+ writer.writerows([input_text,out])
150
+
151
+ return out
152
+
153
  if detail != 1:
154
  Text = summerizer(Text, detail)
155
 
156
  Text, x = study_notes(Text)
157
+
158
 
159
  while x != -1:
160
  response1 = flashcards_maker(Text,x)
 
170
 
171
  listsummery = str(listsummery).replace('\n '," \n")
172
  out = f"{listsummery}"
173
+ if Spend_input_data_API_key_is_not_safed == True:
174
+ with open('\\flashcard_data.csv', 'a', newline='') as csvfile:
175
+ writer = csv.writer(csvfile)
176
+
177
+ writer.writerows([input_text,out])
178
 
179
+ return out
180
+
181
+
182
+
183
+
184
 
185
+ iface =gr.Interface(fn = maker, allow_flagging= "never", inputs=
186
+ [
187
+ gr.Textbox(),
188
+ gr.Dropdown(["flashcards", "concepts cards", "flashcards with topics"]),
189
+ gr.Textbox( label = "Input Text", lines=10, placeholder="Enter your text here..."),
190
+ gr.Dropdown(["No summersiation", "low summersation", "medium summersation", "high summersation"]),
191
+ gr.Checkbox(value = True)
192
+ ],
193
+ outputs = "text", title = "Study cards maker", description= "This tool uses openAI GPT-3 to make study cards for you. This include flashcards, super usefull for Remnotes(reday to copy past). Please use yoru Openai api key. Which you get by sining up at https://beta.openai.com/ "
194
+ )
195
 
196
+ if __name__ == "__main__":
197
+ iface.launch()