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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -32,14 +32,15 @@ generator = load_text_generator()
32
  # Idea Generation Functions
33
  # ---------------------------
34
  def generate_ideas_with_hf(prompt):
35
- # Use Hugging Face's text-generation pipeline (less creative than GPT‑3.5)
36
- results = generator(prompt, max_length=150, num_return_sequences=1)
 
37
  idea_text = results[0]['generated_text']
38
  return idea_text
39
 
40
  def generate_ideas_with_openai(prompt, api_key):
41
  """
42
- Generates research ideas using OpenAI's GPT3.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
@@ -190,15 +191,14 @@ if st.button("Generate Knowledge Graph"):
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():
 
32
  # Idea Generation Functions
33
  # ---------------------------
34
  def generate_ideas_with_hf(prompt):
35
+ # Use Hugging Face's text-generation pipeline.
36
+ # Instead of using max_length, we use max_new_tokens so that new tokens are generated.
37
+ results = generator(prompt, max_new_tokens=50, num_return_sequences=1)
38
  idea_text = results[0]['generated_text']
39
  return idea_text
40
 
41
  def generate_ideas_with_openai(prompt, api_key):
42
  """
43
+ Generates research ideas using OpenAI's GPT-3.5 model with streaming.
44
  This function uses the latest OpenAI SDK v1.0 and asynchronous API calls.
45
  """
46
  openai.api_key = api_key
 
191
  # Build a directed graph using NetworkX
192
  G = nx.DiGraph()
193
  for paper in data:
194
+ # Ensure each node has a 'title' key, using the node id as fallback.
195
+ G.add_node(paper["paper_id"], title=paper.get("title", str(paper["paper_id"])))
196
  for cited in paper["cited"]:
197
  G.add_edge(paper["paper_id"], cited)
198
 
199
  st.subheader("Knowledge Graph")
200
  # Create an interactive visualization using Pyvis
201
  net = Network(height="500px", width="100%", directed=True)
 
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():