ziyadsuper2017 commited on
Commit
c3cd834
·
1 Parent(s): 16bd861

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import the necessary modules
2
+ import google.generativeai as genai
3
+ import streamlit as st
4
+
5
+ # Configure the google-generativeai library by providing your API key
6
+ genai.configure(api_key="AIzaSyC70u1sN87IkoxOoIj4XCAPw97ae2LZwNM")
7
+
8
+ # Set up the model
9
+ generation_config = {
10
+ "temperature": 0.9,
11
+ "top_p": 1,
12
+ "top_k": 1,
13
+ "max_output_tokens": 2048,
14
+ }
15
+
16
+ safety_settings = [
17
+ {
18
+ "category": "HARM_CATEGORY_HARASSMENT",
19
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
20
+ },
21
+ {
22
+ "category": "HARM_CATEGORY_HATE_SPEECH",
23
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
24
+ },
25
+ {
26
+ "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
27
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
28
+ },
29
+ {
30
+ "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
31
+ "threshold": "BLOCK_MEDIUM_AND_ABOVE"
32
+ }
33
+ ]
34
+
35
+ model = genai.GenerativeModel(model_name="gemini-pro",
36
+ generation_config=generation_config,
37
+ safety_settings=safety_settings)
38
+
39
+ # Create a streamlit interface with a title, a description, an input box, and an output box
40
+ st.title("Gemini API") # the title of the interface
41
+ st.markdown("A simple interface for Gemini API that explains code snippets in natural language.") # the description of the interface
42
+ user_input = st.text_area("User Input", height=200) # the input box for the user input
43
+ if st.button("Generate"): # the button to trigger the generation
44
+ # Start a chat session with the model
45
+ convo = model.start_chat(history=[])
46
+ # Send the user input to the model
47
+ convo.send_message(user_input)
48
+ # Get the response from the model
49
+ response = convo.last.text
50
+ # Display the response in the output box
51
+ st.text_area("Response", response, height=200) # the output box for the response