# -*- coding: utf-8 -*- """Untitled28.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/1RXiaLZbGoqx1ruqk83PmIcGRn3gdbbwq """ import streamlit as st import google.generativeai as genai import requests # GenAI API anahtarını yapılandır genai.configure(api_key='AIzaSyDmDtBz5Q96JzzJHojpyR2m0KJ44TKaZm8') # Holiday API anahtarını ayarla holiday_api_key = 'a7ffbb5e-34de-4934-a4fa-3a35de185646' holiday_api_url = 'https://holidayapi.com/v1/holidays' # Uygulama başlığı st.title('Test Deneme') # GenAI modeli model = genai.GenerativeModel('gemini-1.5-pro-latest') # Sohbet geçmişini tutmak için bir oturum durumu başlat if 'chat' not in st.session_state: st.session_state.chat = model.start_chat(history=[]) # Kullanıcıdan soru al soru = st.text_input('You:') if st.button('Ask'): response = st.session_state.chat.send_message(soru) st.write(response.text) st.session_state.chat.history.append({'role': 'user', 'content': soru}) st.session_state.chat.history.append({'role': 'assistant', 'content': response.text}) for message in st.session_state.chat.history: st.write(message['role'] + ':', message['content']) if st.button('New Chat'): st.session_state.chat = model.start_chat(history=[]) # Holiday API ile tatil bilgilerini almak için tarih ve ülke girişi st.header('Holiday Information') date = st.text_input('Enter a date (YYYY-MM-DD):') country = st.text_input('Enter a country code (e.g., US, TR):') if st.button('Get Holidays'): if date and country: params = { 'key': holiday_api_key, 'country': country, 'year': date.split('-')[0], 'month': date.split('-')[1], 'day': date.split('-')[2] } # API'ye istek yap ve yanıtı al response = requests.get(holiday_api_url, params=params) # API isteğini ve yanıtını logla st.write('API Request URL:', response.url) st.write('API Response Status Code:', response.status_code) st.write('API Response JSON:', response.json()) if response.status_code == 200: holidays = response.json().get('holidays', []) if holidays: st.write('Holidays on', date, 'in', country + ':') for holiday in holidays: st.write(holiday['name']) else: st.write('No holidays found on this date in the specified country.') else: st.write('Error:', response.status_code) else: st.write('Please enter both a date and a country code.')