Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
41 |
-
|
42 |
-
|
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 |
|