Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -72,6 +72,7 @@ def extract_text_from_pdf(file):
|
|
| 72 |
def generate_summary_and_keywords(text, summary_lang, style, char_limit):
|
| 73 |
prompt_template = PROMPT_TEMPLATES.get(summary_lang, PROMPT_TEMPLATES["English"])
|
| 74 |
prompt = prompt_template.format(style=style, char_limit=char_limit, text=text[:2000])
|
|
|
|
| 75 |
try:
|
| 76 |
response = client.chat.completions.create(
|
| 77 |
model="gpt-3.5-turbo",
|
|
@@ -79,12 +80,14 @@ def generate_summary_and_keywords(text, summary_lang, style, char_limit):
|
|
| 79 |
temperature=0.7,
|
| 80 |
max_tokens=700
|
| 81 |
)
|
|
|
|
| 82 |
return response.choices[0].message.content
|
| 83 |
except Exception as e:
|
| 84 |
return f"OpenAI error: {str(e)}"
|
| 85 |
|
| 86 |
def generate_quiz(summary_text, summary_lang):
|
| 87 |
quiz_prompt = QUIZ_PROMPTS.get(summary_lang, QUIZ_PROMPTS["English"]).format(text=summary_text)
|
|
|
|
| 88 |
try:
|
| 89 |
response = client.chat.completions.create(
|
| 90 |
model="gpt-3.5-turbo",
|
|
@@ -92,6 +95,7 @@ def generate_quiz(summary_text, summary_lang):
|
|
| 92 |
temperature=0.7,
|
| 93 |
max_tokens=500
|
| 94 |
)
|
|
|
|
| 95 |
return response.choices[0].message.content
|
| 96 |
except Exception as e:
|
| 97 |
return f"OpenAI quiz error: {str(e)}"
|
|
@@ -113,12 +117,12 @@ def process_input(text_input, pdf_file, summary_lang, style, char_limit, quiz_ch
|
|
| 113 |
summary = generate_summary_and_keywords(text, summary_lang, style, char_limit)
|
| 114 |
if quiz_check:
|
| 115 |
quiz = generate_quiz(summary, summary_lang)
|
| 116 |
-
return summary + "\n\n📘 Quiz Questions:\n" + quiz
|
| 117 |
else:
|
| 118 |
return summary
|
| 119 |
|
| 120 |
with gr.Blocks() as demo:
|
| 121 |
-
gr.Markdown("##
|
| 122 |
|
| 123 |
with gr.Row():
|
| 124 |
summary_lang = gr.Dropdown(choices=LANGUAGES, value="English", label="Summary Language")
|
|
@@ -131,12 +135,12 @@ with gr.Blocks() as demo:
|
|
| 131 |
text_input = gr.Textbox(lines=8, placeholder="Paste your text here...", label="Text Input")
|
| 132 |
pdf_file = gr.File(label="Or Upload PDF")
|
| 133 |
|
| 134 |
-
output = gr.
|
| 135 |
|
| 136 |
run_btn = gr.Button("Summarize")
|
| 137 |
|
| 138 |
run_btn.click(fn=process_input,
|
| 139 |
inputs=[text_input, pdf_file, summary_lang, summary_style, char_limit, quiz_check],
|
| 140 |
-
outputs=output)
|
| 141 |
|
| 142 |
demo.launch()
|
|
|
|
| 72 |
def generate_summary_and_keywords(text, summary_lang, style, char_limit):
|
| 73 |
prompt_template = PROMPT_TEMPLATES.get(summary_lang, PROMPT_TEMPLATES["English"])
|
| 74 |
prompt = prompt_template.format(style=style, char_limit=char_limit, text=text[:2000])
|
| 75 |
+
print("🔹 PROMPT 1:", prompt)
|
| 76 |
try:
|
| 77 |
response = client.chat.completions.create(
|
| 78 |
model="gpt-3.5-turbo",
|
|
|
|
| 80 |
temperature=0.7,
|
| 81 |
max_tokens=700
|
| 82 |
)
|
| 83 |
+
print("✅ RESPONSE 1:", response.choices[0].message.content)
|
| 84 |
return response.choices[0].message.content
|
| 85 |
except Exception as e:
|
| 86 |
return f"OpenAI error: {str(e)}"
|
| 87 |
|
| 88 |
def generate_quiz(summary_text, summary_lang):
|
| 89 |
quiz_prompt = QUIZ_PROMPTS.get(summary_lang, QUIZ_PROMPTS["English"]).format(text=summary_text)
|
| 90 |
+
print("🔹 PROMPT 2:", quiz_prompt)
|
| 91 |
try:
|
| 92 |
response = client.chat.completions.create(
|
| 93 |
model="gpt-3.5-turbo",
|
|
|
|
| 95 |
temperature=0.7,
|
| 96 |
max_tokens=500
|
| 97 |
)
|
| 98 |
+
print("✅ RESPONSE 2:", response.choices[0].message.content)
|
| 99 |
return response.choices[0].message.content
|
| 100 |
except Exception as e:
|
| 101 |
return f"OpenAI quiz error: {str(e)}"
|
|
|
|
| 117 |
summary = generate_summary_and_keywords(text, summary_lang, style, char_limit)
|
| 118 |
if quiz_check:
|
| 119 |
quiz = generate_quiz(summary, summary_lang)
|
| 120 |
+
return summary + "\n\n### 📘 Quiz Questions:\n" + quiz
|
| 121 |
else:
|
| 122 |
return summary
|
| 123 |
|
| 124 |
with gr.Blocks() as demo:
|
| 125 |
+
gr.Markdown("## 📚 Two-Step Summarizer with Markdown Output")
|
| 126 |
|
| 127 |
with gr.Row():
|
| 128 |
summary_lang = gr.Dropdown(choices=LANGUAGES, value="English", label="Summary Language")
|
|
|
|
| 135 |
text_input = gr.Textbox(lines=8, placeholder="Paste your text here...", label="Text Input")
|
| 136 |
pdf_file = gr.File(label="Or Upload PDF")
|
| 137 |
|
| 138 |
+
output = gr.Markdown(label="Output")
|
| 139 |
|
| 140 |
run_btn = gr.Button("Summarize")
|
| 141 |
|
| 142 |
run_btn.click(fn=process_input,
|
| 143 |
inputs=[text_input, pdf_file, summary_lang, summary_style, char_limit, quiz_check],
|
| 144 |
+
outputs=[output])
|
| 145 |
|
| 146 |
demo.launch()
|