Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pathlib | |
| import textwrap | |
| import google.generativeai as genai | |
| def to_markdown(text): | |
| text = text.replace('•', ' *') | |
| return textwrap.indent(text, '> ', lambda line: True) | |
| def chat(prompt): | |
| genai.configure(api_key='AIzaSyCMBk81YmILNTok8hd6tYtJaevp1qbl6I0') | |
| text_model = genai.GenerativeModel('gemini-pro') | |
| try: | |
| response = text_model.generate_content(prompt, stream=True) | |
| return to_markdown(response.text) | |
| except Exception as e: | |
| print(f"Error during generation: {e}") | |
| return "An error occurred while generating the response. Please try again later." | |
| st.title("AI Jokes Maker") | |
| st.write("Just enter topic for joke and I'll generate you 5 jokes on this topic ✨") | |
| er, mr = st.columns(2) | |
| with er: | |
| prompt = st.text_input("Enter topic") | |
| if st.button("Generate ✨"): | |
| res = chat("Generate 5 funny jokes on this topic: " + prompt) | |
| if res: | |
| with mr: | |
| st.write(res) |