Spaces:
Sleeping
Sleeping
Commit
•
8ed9429
1
Parent(s):
1e2e8cd
Update app.py
Browse files
app.py
CHANGED
@@ -9,17 +9,13 @@ def to_markdown(text):
|
|
9 |
return textwrap.indent(text, '> ', predicate=lambda _: True)
|
10 |
|
11 |
# Function to generate content using Gemini API
|
12 |
-
def generate_gemini_content(prompt, model_name='gemini-pro', image=None):
|
13 |
model = genai.GenerativeModel(model_name)
|
14 |
-
if
|
15 |
st.warning("Please add an image to use the gemini-pro-vision model.")
|
16 |
return None
|
17 |
|
18 |
-
|
19 |
-
response = model.generate_content([prompt, image])
|
20 |
-
else:
|
21 |
-
response = model.generate_content(prompt)
|
22 |
-
|
23 |
return response
|
24 |
|
25 |
# Streamlit app
|
@@ -30,8 +26,8 @@ def main():
|
|
30 |
api_key = st.text_input("Enter your Gemini API key:")
|
31 |
genai.configure(api_key=api_key)
|
32 |
|
33 |
-
#
|
34 |
-
model_name =
|
35 |
|
36 |
# Get user input prompt
|
37 |
prompt = st.text_area("Enter your prompt:")
|
@@ -46,23 +42,20 @@ def main():
|
|
46 |
# Generate content on button click
|
47 |
if st.button("Generate Content"):
|
48 |
st.markdown("### Generated Content:")
|
49 |
-
if
|
50 |
-
|
51 |
-
st.warning("Please provide an image for the gemini-pro-vision model.")
|
52 |
-
else:
|
53 |
-
image = Image.open(image_file)
|
54 |
-
response = generate_gemini_content(prompt, model_name=model_name, image=image)
|
55 |
else:
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
if response
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
66 |
|
67 |
if __name__ == "__main__":
|
68 |
main()
|
|
|
9 |
return textwrap.indent(text, '> ', predicate=lambda _: True)
|
10 |
|
11 |
# Function to generate content using Gemini API
|
12 |
+
def generate_gemini_content(prompt, model_name='gemini-pro-vision', image=None):
|
13 |
model = genai.GenerativeModel(model_name)
|
14 |
+
if not image:
|
15 |
st.warning("Please add an image to use the gemini-pro-vision model.")
|
16 |
return None
|
17 |
|
18 |
+
response = model.generate_content([prompt, image])
|
|
|
|
|
|
|
|
|
19 |
return response
|
20 |
|
21 |
# Streamlit app
|
|
|
26 |
api_key = st.text_input("Enter your Gemini API key:")
|
27 |
genai.configure(api_key=api_key)
|
28 |
|
29 |
+
# Set the model to 'gemini-pro-vision'
|
30 |
+
model_name = 'gemini-pro-vision'
|
31 |
|
32 |
# Get user input prompt
|
33 |
prompt = st.text_area("Enter your prompt:")
|
|
|
42 |
# Generate content on button click
|
43 |
if st.button("Generate Content"):
|
44 |
st.markdown("### Generated Content:")
|
45 |
+
if not image_file:
|
46 |
+
st.warning("Please provide an image for the gemini-pro-vision model.")
|
|
|
|
|
|
|
|
|
47 |
else:
|
48 |
+
image = Image.open(image_file)
|
49 |
+
response = generate_gemini_content(prompt, model_name=model_name, image=image)
|
50 |
+
|
51 |
+
# Display the generated content in Markdown format if response is available
|
52 |
+
if response:
|
53 |
+
if response.candidates:
|
54 |
+
parts = response.candidates[0].content.parts
|
55 |
+
generated_text = parts[0].text if parts else "No content generated."
|
56 |
+
st.markdown(to_markdown(generated_text))
|
57 |
+
else:
|
58 |
+
st.warning("No candidates found in the response.")
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
main()
|