mgbam commited on
Commit
bbccbee
·
verified ·
1 Parent(s): 0572bba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -21,7 +21,7 @@ def load_summarizer():
21
 
22
  @st.cache_resource(show_spinner=False)
23
  def load_text_generator():
24
- # For demonstration, we load a text-generation model such as GPT-2
25
  generator = pipeline("text-generation", model="gpt2")
26
  return generator
27
 
@@ -40,7 +40,7 @@ def generate_ideas_with_hf(prompt):
40
  def generate_ideas_with_openai(prompt, api_key):
41
  """
42
  Generates research ideas using OpenAI's GPT‑3.5 model with streaming.
43
- This function uses the latest OpenAI SDK v1.0 which supports asynchronous API calls.
44
  """
45
  openai.api_key = api_key
46
  output_text = ""
@@ -139,13 +139,13 @@ paper_abstract = st.text_area("Enter the research paper abstract:", height=200)
139
  if st.button("Generate Ideas"):
140
  if paper_abstract.strip():
141
  st.subheader("Summarized Abstract")
142
- # Use the Hugging Face summarizer to capture key points
143
  summary = summarizer(paper_abstract, max_length=100, min_length=30, do_sample=False)
144
  summary_text = summary[0]['summary_text']
145
  st.write(summary_text)
146
 
147
  st.subheader("Generated Research Ideas")
148
- # Build a combined prompt based on the abstract and its summary
149
  prompt = (
150
  f"Based on the following research paper abstract, generate innovative and promising research ideas for future work.\n\n"
151
  f"Paper Abstract:\n{paper_abstract}\n\n"
@@ -169,8 +169,9 @@ if st.button("Generate Ideas"):
169
  # --- Section 3: Knowledge Graph Visualization ---
170
  st.header("Knowledge Graph Visualization")
171
  st.markdown(
172
- "Simulate a knowledge graph by entering paper details and their citation relationships in CSV format: **PaperID,Title,CitedPaperIDs** (CitedPaperIDs separated by ';').\n\n"
173
- "Example:\n\n`1,Paper A,2;3`\n`2,Paper B,`\n`3,Paper C,2`"
 
174
  )
175
  papers_csv = st.text_area("Enter paper details in CSV format:", height=150)
176
 
@@ -189,15 +190,17 @@ if st.button("Generate Knowledge Graph"):
189
  # Build a directed graph using NetworkX
190
  G = nx.DiGraph()
191
  for paper in data:
192
- G.add_node(paper["paper_id"], title=paper["title"])
 
193
  for cited in paper["cited"]:
194
  G.add_edge(paper["paper_id"], cited)
195
 
196
  st.subheader("Knowledge Graph")
197
  # Create an interactive visualization using Pyvis
198
  net = Network(height="500px", width="100%", directed=True)
 
199
  for node, node_data in G.nodes(data=True):
200
- net.add_node(node, label=node_data["title"])
201
  for source, target in G.edges():
202
  net.add_edge(source, target)
203
  # Save the interactive visualization to an HTML file and embed it in Streamlit
 
21
 
22
  @st.cache_resource(show_spinner=False)
23
  def load_text_generator():
24
+ # For demonstration, we load a text-generation model such as GPT-2.
25
  generator = pipeline("text-generation", model="gpt2")
26
  return generator
27
 
 
40
  def generate_ideas_with_openai(prompt, api_key):
41
  """
42
  Generates research ideas using OpenAI's GPT‑3.5 model with streaming.
43
+ This function uses the latest OpenAI SDK v1.0 and asynchronous API calls.
44
  """
45
  openai.api_key = api_key
46
  output_text = ""
 
139
  if st.button("Generate Ideas"):
140
  if paper_abstract.strip():
141
  st.subheader("Summarized Abstract")
142
+ # Summarize the abstract to capture its key points
143
  summary = summarizer(paper_abstract, max_length=100, min_length=30, do_sample=False)
144
  summary_text = summary[0]['summary_text']
145
  st.write(summary_text)
146
 
147
  st.subheader("Generated Research Ideas")
148
+ # Build a combined prompt with the abstract and its summary
149
  prompt = (
150
  f"Based on the following research paper abstract, generate innovative and promising research ideas for future work.\n\n"
151
  f"Paper Abstract:\n{paper_abstract}\n\n"
 
169
  # --- Section 3: Knowledge Graph Visualization ---
170
  st.header("Knowledge Graph Visualization")
171
  st.markdown(
172
+ "Simulate a knowledge graph by entering paper details and their citation relationships in CSV format:\n\n"
173
+ "**PaperID,Title,CitedPaperIDs** (CitedPaperIDs separated by ';').\n\n"
174
+ "Example:\n\n```\n1,Paper A,2;3\n2,Paper B,\n3,Paper C,2\n```"
175
  )
176
  papers_csv = st.text_area("Enter paper details in CSV format:", height=150)
177
 
 
190
  # Build a directed graph using NetworkX
191
  G = nx.DiGraph()
192
  for paper in data:
193
+ # Ensure each node has a 'title' key, even if it's an empty string.
194
+ G.add_node(paper["paper_id"], title=paper.get("title", ""))
195
  for cited in paper["cited"]:
196
  G.add_edge(paper["paper_id"], cited)
197
 
198
  st.subheader("Knowledge Graph")
199
  # Create an interactive visualization using Pyvis
200
  net = Network(height="500px", width="100%", directed=True)
201
+ # Use get() to avoid KeyError and provide a fallback label.
202
  for node, node_data in G.nodes(data=True):
203
+ net.add_node(node, label=node_data.get("title", str(node)))
204
  for source, target in G.edges():
205
  net.add_edge(source, target)
206
  # Save the interactive visualization to an HTML file and embed it in Streamlit