Download app.py from srinitish/GenAi: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/srinitish/GenAi/resolve/main/app.py
- Command line
-
hf download hf://spaces/srinitish/GenAi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/srinitish/GenAi/resolve/main/app.py
1.21 kB
| import os | |
| import google.generativeai as genai | |
| import gradio as gr | |
| genai.configure(api_key="AIzaSyBYwBXI_qd4CL-xb8e39R_akVzWzVSHkhA") | |
| generation_config = { | |
| "temperature": 1, | |
| "top_p": 0.95, | |
| "top_k": 0, | |
| "max_output_tokens": 100, | |
| } | |
| safety_settings = [ | |
| {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}, | |
| ] | |
| model = genai.GenerativeModel( | |
| model_name="gemini-1.5-pro-latest", | |
| generation_config=generation_config, | |
| safety_settings=safety_settings | |
| ) | |
| # Start a chat session | |
| chat_session = model.start_chat(history=[]) | |
| def chatbot(user_message): | |
| # Send user message to the chat session | |
| response = chat_session.send_message(user_message) | |
| return response.text | |
| # Define the Gradio interface with a text input and text output | |
| interface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GenAI Chatbot") | |
| # Launch the Gradio interface | |
| interface.launch(share=True) | |