Kvikontent commited on
Commit
6e9b86d
·
verified ·
1 Parent(s): 6e5a651

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pathlib
3
+ import textwrap
4
+ import google.generativeai as genai
5
+
6
+ def to_markdown(text):
7
+ text = text.replace('•', ' *')
8
+ return textwrap.indent(text, '> ', lambda line: True)
9
+
10
+ def chat(prompt):
11
+ genai.configure(api_key='AIzaSyCMBk81YmILNTok8hd6tYtJaevp1qbl6I0')
12
+
13
+ text_model = genai.GenerativeModel('gemini-pro')
14
+
15
+ try:
16
+ response = text_model.generate_content(prompt, stream=True)
17
+
18
+ for chunk in response:
19
+ return to_markdown(chunk.text)
20
+
21
+ except Exception as e:
22
+ print(f"Error during generation: {e}")
23
+ return "An error occurred while generating the response. Please try again later."
24
+
25
+ st.title("AI Jokes Maker")
26
+ st.write("Just enter topic for joke and I'll generate you 5 jokes on this topic ✨")
27
+ er, mr = st.colums(2)
28
+
29
+ with er:
30
+ prompt = st.text_input("Enter topic")
31
+ if st.button("Generate ✨"):
32
+ res = chat("Generate 5 funny jokes on this topic: " + prompt)
33
+ if res:
34
+ with mr:
35
+ st.write(res)