Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,15 @@ client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
|
|
| 9 |
SUMMARY_STYLES = ["Child-Friendly", "Academic", "Tweet"]
|
| 10 |
LANGUAGES = ["English", "Turkish", "Arabic", "French", "German", "Spanish"]
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def extract_text_from_pdf(file):
|
| 13 |
try:
|
| 14 |
with pdfplumber.open(file.name) as pdf:
|
|
@@ -24,23 +33,16 @@ def extract_text_from_pdf(file):
|
|
| 24 |
return None, f"PDF reading error: {str(e)}"
|
| 25 |
|
| 26 |
def generate_output(text, summary_lang, style, char_limit, quiz_check):
|
|
|
|
|
|
|
| 27 |
prompt = f"""
|
| 28 |
You are a helpful assistant.
|
| 29 |
|
| 30 |
Summarize the following text in {summary_lang} using a {style} style.
|
| 31 |
Keep it within approximately {char_limit} characters.
|
| 32 |
Then provide 5 keywords.
|
| 33 |
-
quiz_instruction = {
|
| 34 |
-
"English": "Also generate 2 quiz questions (multiple choice).",
|
| 35 |
-
"Turkish": "Ayrıca 2 adet çoktan seçmeli quiz sorusu da üret.",
|
| 36 |
-
"French": "Générez également 2 questions à choix multiples.",
|
| 37 |
-
"German": "Erzeuge zusätzlich 2 Multiple-Choice-Fragen.",
|
| 38 |
-
"Arabic": "قم بإنشاء سؤالين اختيار من متعدد أيضًا.",
|
| 39 |
-
"Spanish": "También genera 2 preguntas tipo test."
|
| 40 |
-
}
|
| 41 |
|
| 42 |
-
quiz_prompt
|
| 43 |
-
{ quiz_prompt if quiz_check else '' }
|
| 44 |
|
| 45 |
|
| 46 |
TEXT:
|
|
|
|
| 9 |
SUMMARY_STYLES = ["Child-Friendly", "Academic", "Tweet"]
|
| 10 |
LANGUAGES = ["English", "Turkish", "Arabic", "French", "German", "Spanish"]
|
| 11 |
|
| 12 |
+
QUIZ_INSTRUCTIONS = {
|
| 13 |
+
"English": "Also generate 2 quiz questions (multiple choice).",
|
| 14 |
+
"Turkish": "Ayrıca 2 adet çoktan seçmeli quiz sorusu da üret.",
|
| 15 |
+
"French": "Générez également 2 questions à choix multiples.",
|
| 16 |
+
"German": "Erzeuge zusätzlich 2 Multiple-Choice-Fragen.",
|
| 17 |
+
"Arabic": "قم بإنشاء سؤالين اختيار من متعدد أيضًا.",
|
| 18 |
+
"Spanish": "También genera 2 preguntas tipo test."
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
def extract_text_from_pdf(file):
|
| 22 |
try:
|
| 23 |
with pdfplumber.open(file.name) as pdf:
|
|
|
|
| 33 |
return None, f"PDF reading error: {str(e)}"
|
| 34 |
|
| 35 |
def generate_output(text, summary_lang, style, char_limit, quiz_check):
|
| 36 |
+
quiz_prompt = QUIZ_INSTRUCTIONS.get(summary_lang, QUIZ_INSTRUCTIONS["English"]) if quiz_check else ""
|
| 37 |
+
|
| 38 |
prompt = f"""
|
| 39 |
You are a helpful assistant.
|
| 40 |
|
| 41 |
Summarize the following text in {summary_lang} using a {style} style.
|
| 42 |
Keep it within approximately {char_limit} characters.
|
| 43 |
Then provide 5 keywords.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
{quiz_prompt}
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
TEXT:
|