Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,7 +126,37 @@ def add_section_to_doc(doc, section_name, section_content):
|
|
| 126 |
def add_suggested_title(section_name, section_content):
|
| 127 |
suggested_title = f"Suggested Title: {section_name}"
|
| 128 |
return f"{suggested_title}\n\n{section_content}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
def get_docx_bytes(doc):
|
| 131 |
doc_io = io.BytesIO()
|
| 132 |
doc.save(doc_io)
|
|
|
|
| 126 |
def add_suggested_title(section_name, section_content):
|
| 127 |
suggested_title = f"Suggested Title: {section_name}"
|
| 128 |
return f"{suggested_title}\n\n{section_content}"
|
| 129 |
+
def suggest_title(data):
|
| 130 |
+
"""
|
| 131 |
+
Suggests a suitable title for the PhD proposal based on the provided data.
|
| 132 |
+
:param data: Dictionary containing the research topic, question, and other details.
|
| 133 |
+
:return: Suggested title as a string.
|
| 134 |
+
"""
|
| 135 |
+
try:
|
| 136 |
+
prompt = (
|
| 137 |
+
f"Based on the following information, suggest a concise and compelling title for a PhD research proposal:\n\n"
|
| 138 |
+
f"Research Topic: {data.get('research_topic', '')}\n"
|
| 139 |
+
f"Research Question: {data.get('research_question', '')}\n"
|
| 140 |
+
f"Objectives: {data.get('objectives', '')}\n"
|
| 141 |
+
f"Contribution: {data.get('contribution', '')}\n\n"
|
| 142 |
+
"The title should be less than 15 words, clear, and indicative of the research focus."
|
| 143 |
+
)
|
| 144 |
|
| 145 |
+
system_prompt = "You are a title generator for academic PhD proposals. Suggest a concise, impactful title."
|
| 146 |
+
|
| 147 |
+
# Call the LLM to generate the title
|
| 148 |
+
completion = client.chat.completions.create(
|
| 149 |
+
model=utilized_model,
|
| 150 |
+
messages=[
|
| 151 |
+
{"role": "system", "content": system_prompt},
|
| 152 |
+
{"role": "user", "content": prompt},
|
| 153 |
+
]
|
| 154 |
+
)
|
| 155 |
+
return completion.choices[0].message.content.strip()
|
| 156 |
+
|
| 157 |
+
except Exception as e:
|
| 158 |
+
logging.error(f"Error generating title: {str(e)}")
|
| 159 |
+
return "Error: Unable to generate a title at this time."
|
| 160 |
def get_docx_bytes(doc):
|
| 161 |
doc_io = io.BytesIO()
|
| 162 |
doc.save(doc_io)
|