JAMESPARK3 commited on
Commit
d9729f5
ยท
verified ยท
1 Parent(s): b448f16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -39
app.py CHANGED
@@ -156,12 +156,18 @@ st.markdown("""
156
  font-size: 1.5em;
157
  font-weight: bold;
158
  color: #333;
 
 
 
159
  }
160
  @keyframes scrolling {
161
- 0% {transform: translateX(100%);}
162
- 100% {transform: translateX(-100%);}
 
 
163
  }
164
 
 
165
  /* ๋ชจ๋ฐ”์ผ ๋Œ€์‘์„ ์œ„ํ•œ CSS ์ถ”๊ฐ€ */
166
  @media (max-width: 600px) {
167
  .time-container {
@@ -711,48 +717,13 @@ def show_temperature_graph(data):
711
 
712
  # ๋‚ ์”จ ์˜ˆ๋ณด ์ƒ์„ฑ ๋ฐ ํ‘œ์‹œ ๋ถ€๋ถ„์„ ์„ธ์…˜ ์ƒํƒœ๋กœ ๊ด€๋ฆฌ
713
  if 'weather_forecast' not in st.session_state:
714
- client = OpenAI(
715
- api_key="glhf_9ea0e0babe1e45353dd03b44cb979e22",
716
- base_url="https://glhf.chat/api/openai/v1",
717
- http_client=httpx.Client(
718
- follow_redirects=True,
719
- timeout=30.0
720
- )
721
- )
722
-
723
-
724
- # ํ˜„์žฌ ์‹œ๊ฐ„๊ณผ ์˜ˆ๋ณด ์‹œ๊ฐ„ ์ •๋ณด ์ถ”๊ฐ€
725
- current_time = datetime.utcnow() + timedelta(hours=9)
726
- current_date_str = current_time.strftime('%Y๋…„ %m์›” %d์ผ')
727
- tomorrow_date_str = (current_time + timedelta(days=1)).strftime('%Y๋…„ %m์›” %d์ผ')
728
-
729
  forecast_data_str = "\n".join([
730
  f"[{f['FCST_DT'][:4]}๋…„ {f['FCST_DT'][4:6]}์›” {f['FCST_DT'][6:8]}์ผ {f['FCST_DT'][8:10]}์‹œ] {temp}๋„, {description}"
731
  for f, time, temp, description in zip(valid_forecast_data, times, temps, weather_descriptions)
732
  ])
733
 
734
- response = client.chat.completions.create(
735
- model="hf:Nexusflow/Athene-V2-Chat",
736
- messages=[
737
- {"role": "system", "content": "๋‹น์‹ ์€ ๋‚ ์”จ ์˜ˆ๋ณด๊ด€์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์‹œ๊ฐ„๋Œ€๋ณ„ ๋‚ ์”จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ •ํ™•ํ•œ ๋‚ ์”จ ์˜ˆ๋ณด๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."},
738
- {"role": "user", "content": f"""ํ˜„์žฌ ์‹œ๊ฐ์€ {current_time.strftime('%H์‹œ %M๋ถ„')}์ž…๋‹ˆ๋‹ค.
739
-
740
- ๋‹ค์Œ FCST_DT์˜ ์‹œ๊ฐ„๋Œ€๋ณ„ ๋‚ ์”จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ์‹ค์ œ ๋‚ ์”จ ์ƒํ™ฉ์— ๋งž๋Š” ์ •ํ™•ํ•œ ๋‚ ์”จ ์˜ˆ๋ณด๋ฅผ 200์ž์˜ ์ž์—ฐ์Šค๋Ÿฌ์šด ๋ฌธ์žฅ์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”. ๋น„๋‚˜ ๋ˆˆ ์˜ˆ๋ณด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ์šฐ์‚ฐ์„ ์ค€๋น„ํ•˜๋„๋ก ์•ˆ๋‚ดํ•ด์ฃผ์„ธ์š”. ์˜ท์ฐจ๋ฆผ์€ ๋‹ค์Œ์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.
741
- 27ยฐC์ด์ƒ: ๋ฐ˜ํŒ”ํ‹ฐ, ๋ฐ˜๋ฐ”์ง€, ๋ฏผ์†Œ๋งค
742
- 23ยฐC~26ยฐC: ์–‡์€ ์…”์ธ , ๋ฐ˜ํŒ”ํ‹ฐ, ๋ฐ˜๋ฐ”์ง€, ๋ฉด๋ฐ”์ง€
743
- 20ยฐC~22ยฐC: ์–‡์€ ๊ฐ€๋””๊ฑด, ๊ธดํŒ”ํ‹ฐ, ๊ธด๋ฐ”์ง€
744
- 17ยฐC~19ยฐC: ์–‡์€ ๋‹ˆํŠธ, ๊ฐ€๋””๊ฑด, ๋งจํˆฌ๋งจ, ์–‡์€ ์ž์ผ“, ๊ธด๋ฐ”์ง€
745
- 12ยฐC~16ยฐC: ์ž์ผ“, ๊ฐ€๋””๊ฑด, ์•ผ์ƒ, ๋งจํˆฌ๋งจ, ๋‹ˆํŠธ, ์Šคํƒ€ํ‚น, ๊ธด๋ฐ”์ง€
746
- 9ยฐC~11ยฐC: ํŠธ๋ Œ์น˜์ฝ”ํŠธ, ์•ผ์ƒ, ๊ฐ€์ฃฝ ์ž์ผ“, ์Šคํƒ€ํ‚น, ๊ธด๋ฐ”์ง€
747
- 5ยฐC~8ยฐC: ์ฝ”ํŠธ, ํžˆํŠธํ…, ๋‹ˆํŠธ, ๊ธด๋ฐ”์ง€
748
- 4ยฐC์ดํ•˜: ํŒจ๋”ฉ, ๋‘๊บผ์šด ์ฝ”ํŠธ, ๋ชฉ๋„๋ฆฌ, ๊ธฐ๋ชจ์ œํ’ˆ
749
-
750
- ์‹œ๊ฐ„๋Œ€๋ณ„ ๋‚ ์”จ ๋ฐ์ดํ„ฐ:
751
- {forecast_data_str}"""}
752
- ]
753
- )
754
-
755
- st.session_state.weather_forecast = response.choices[0].message.content
756
 
757
  # ์ €์žฅ๋œ ๋‚ ์”จ ์˜ˆ๋ณด ํ‘œ์‹œ
758
  st.markdown(f'''
@@ -771,6 +742,40 @@ def show_temperature_graph(data):
771
 
772
  st.markdown('</div>', unsafe_allow_html=True)
773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
  def main():
775
  if 'current_section' not in st.session_state:
776
  st.session_state.current_section = 'weather'
 
156
  font-size: 1.5em;
157
  font-weight: bold;
158
  color: #333;
159
+ position: relative;
160
+ left: 50%;
161
+ transform: translateX(-50%);
162
  }
163
  @keyframes scrolling {
164
+ 0% {transform: translateX(0%); opacity: 0;}
165
+ 10% {opacity: 1;}
166
+ 90% {opacity: 1;}
167
+ 100% {transform: translateX(-100%); opacity: 0;}
168
  }
169
 
170
+
171
  /* ๋ชจ๋ฐ”์ผ ๋Œ€์‘์„ ์œ„ํ•œ CSS ์ถ”๊ฐ€ */
172
  @media (max-width: 600px) {
173
  .time-container {
 
717
 
718
  # ๋‚ ์”จ ์˜ˆ๋ณด ์ƒ์„ฑ ๋ฐ ํ‘œ์‹œ ๋ถ€๋ถ„์„ ์„ธ์…˜ ์ƒํƒœ๋กœ ๊ด€๋ฆฌ
719
  if 'weather_forecast' not in st.session_state:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
  forecast_data_str = "\n".join([
721
  f"[{f['FCST_DT'][:4]}๋…„ {f['FCST_DT'][4:6]}์›” {f['FCST_DT'][6:8]}์ผ {f['FCST_DT'][8:10]}์‹œ] {temp}๋„, {description}"
722
  for f, time, temp, description in zip(valid_forecast_data, times, temps, weather_descriptions)
723
  ])
724
 
725
+ current_time_str = current_time.strftime('%H์‹œ %M๋ถ„')
726
+ st.session_state.weather_forecast = get_weather_forecast(forecast_data_str, current_time_str)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
727
 
728
  # ์ €์žฅ๋œ ๋‚ ์”จ ์˜ˆ๋ณด ํ‘œ์‹œ
729
  st.markdown(f'''
 
742
 
743
  st.markdown('</div>', unsafe_allow_html=True)
744
 
745
+ @st.cache_data(ttl=300) # 5๋ถ„ ์บ์‹œ
746
+ def get_weather_forecast(forecast_data_str, current_time_str):
747
+ client = OpenAI(
748
+ api_key="glhf_9ea0e0babe1e45353dd03b44cb979e22",
749
+ base_url="https://glhf.chat/api/openai/v1",
750
+ http_client=httpx.Client(
751
+ follow_redirects=True,
752
+ timeout=30.0
753
+ )
754
+ )
755
+
756
+ response = client.chat.completions.create(
757
+ model="hf:Nexusflow/Athene-V2-Chat",
758
+ messages=[
759
+ {"role": "system", "content": "๋‹น์‹ ์€ ๋‚ ์”จ ์˜ˆ๋ณด๊ด€์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์‹œ๊ฐ„๋Œ€๋ณ„ ๋‚ ์”จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ •ํ™•ํ•œ ๋‚ ์”จ ์˜ˆ๋ณด๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”."},
760
+ {"role": "user", "content": f"""ํ˜„์žฌ ์‹œ๊ฐ์€ {current_time_str}์ž…๋‹ˆ๋‹ค.
761
+
762
+ ๋‹ค์Œ FCST_DT์˜ ์‹œ๊ฐ„๋Œ€๋ณ„ ๋‚ ์”จ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๊ณ  ์‹ค์ œ ๋‚ ์”จ ์ƒํ™ฉ์— ๋งž๋Š” ์ •ํ™•ํ•œ ๋‚ ์”จ ์˜ˆ๋ณด๋ฅผ 200์ž์˜ ์ž์—ฐ์Šค๋Ÿฌ์šด ๋ฌธ์žฅ์œผ๋กœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”. ๋น„๋‚˜ ๋ˆˆ ์˜ˆ๋ณด๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ์šฐ์‚ฐ์„ ์ค€๋น„ํ•˜๋„๋ก ์•ˆ๋‚ดํ•ด์ฃผ์„ธ์š”. ์˜ท์ฐจ๋ฆผ์€ ๋‹ค์Œ์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.
763
+ 27ยฐC์ด์ƒ: ๋ฐ˜ํŒ”ํ‹ฐ, ๋ฐ˜๋ฐ”์ง€, ๋ฏผ์†Œ๋งค
764
+ 23ยฐC~26ยฐC: ์–‡์€ ์…”์ธ , ๋ฐ˜ํŒ”ํ‹ฐ, ๋ฐ˜๋ฐ”์ง€, ๋ฉด๋ฐ”์ง€
765
+ 20ยฐC~22ยฐC: ์–‡์€ ๊ฐ€๋””๊ฑด, ๊ธดํŒ”ํ‹ฐ, ๊ธด๋ฐ”์ง€
766
+ 17ยฐC~19ยฐC: ์–‡์€ ๋‹ˆํŠธ, ๊ฐ€๋””๊ฑด, ๋งจํˆฌ๋งจ, ์–‡์€ ์ž์ผ“, ๊ธด๋ฐ”์ง€
767
+ 12ยฐC~16ยฐC: ์ž์ผ“, ๊ฐ€๋””๊ฑด, ์•ผ์ƒ, ๋งจํˆฌ๋งจ, ๋‹ˆํŠธ, ์Šคํƒ€ํ‚น, ๊ธด๋ฐ”์ง€
768
+ 9ยฐC~11ยฐC: ํŠธ๋ Œ์น˜์ฝ”ํŠธ, ์•ผ์ƒ, ๊ฐ€์ฃฝ ์ž์ผ“, ์Šคํƒ€ํ‚น, ๊ธด๋ฐ”์ง€
769
+ 5ยฐC~8ยฐC: ์ฝ”ํŠธ, ํžˆํŠธํ…, ๋‹ˆํŠธ, ๊ธด๋ฐ”์ง€
770
+ 4ยฐC์ดํ•˜: ํŒจ๋”ฉ, ๋‘๊บผ์šด ์ฝ”ํŠธ, ๋ชฉ๋„๋ฆฌ, ๊ธฐ๋ชจ์ œํ’ˆ
771
+
772
+ ์‹œ๊ฐ„๋Œ€๋ณ„ ๋‚ ์”จ ๋ฐ์ดํ„ฐ:
773
+ {forecast_data_str}"""}
774
+ ]
775
+ )
776
+ return response.choices[0].message.content
777
+
778
+
779
  def main():
780
  if 'current_section' not in st.session_state:
781
  st.session_state.current_section = 'weather'