Spaces:
Runtime error
Runtime error
Commit ·
40b5c39
1
Parent(s): 7aa3b21
try
Browse files
main.py
CHANGED
|
@@ -1,7 +1,21 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
def
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
def main():
|
| 6 |
+
GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY')
|
| 7 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 8 |
+
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 9 |
+
|
| 10 |
+
if prompt := st.chat_input("哈囉!請問有什麼是我可以幫忙的嗎?"):
|
| 11 |
+
with st.chat_message("user"):
|
| 12 |
+
st.markdown(prompt)
|
| 13 |
|
| 14 |
+
with st.chat_message("assistant"):
|
| 15 |
+
def reply():
|
| 16 |
+
for chunk in model.generate_content(contents=prompt, stream=True):
|
| 17 |
+
yield chunk.text
|
| 18 |
+
st.write_stream(reply)
|
| 19 |
+
|
| 20 |
+
if __name__=="__main__":
|
| 21 |
+
main()
|