Patrick079 commited on
Commit
9da51e4
·
verified ·
1 Parent(s): de94616

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -3,6 +3,8 @@ import os
3
  import gradio as gr
4
  import google.generativeai as genai # Importing the Gemini API module
5
 
 
 
6
 
7
  def chat_short_story(length, genre, theme, tone, writing_style):
8
  """
@@ -37,11 +39,9 @@ def chat_short_story(length, genre, theme, tone, writing_style):
37
 
38
  # Generate a response using the Gemini model
39
  try:
40
- response = genai.generate_text(prompt=prompt, model="gemini-1.5-flash")
41
- if "candidates" in response and len(response["candidates"]) > 0:
42
- return response["candidates"][0]["output"] # Extract the story content
43
- else:
44
- return "Error: No story generated. Please check your input or try again."
45
  except Exception as e:
46
  return f"Error: Failed to generate story. Details: {e}"
47
 
 
3
  import gradio as gr
4
  import google.generativeai as genai # Importing the Gemini API module
5
 
6
+ # Initialize the Gemini model
7
+ Model = genai.GenerativeModel('gemini-1.5-flash') # Initialize the generative model
8
 
9
  def chat_short_story(length, genre, theme, tone, writing_style):
10
  """
 
39
 
40
  # Generate a response using the Gemini model
41
  try:
42
+ chat = Model.start_chat() # Start a chat session
43
+ response = chat.send_message(prompt) # Send the prompt to the model
44
+ return response.text # Extract the content of the response
 
 
45
  except Exception as e:
46
  return f"Error: Failed to generate story. Details: {e}"
47