yunuseduran commited on
Commit
b59f787
·
verified ·
1 Parent(s): 8cb8cde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -4
app.py CHANGED
@@ -1,3 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/usr/bin/env python
2
  # coding: utf-8
3
 
@@ -10,7 +52,7 @@ logging.set_verbosity_error()
10
  import os
11
  genai.configure(api_key=os.getenv("key"))
12
 
13
- st.title('ask me a question')
14
  model = genai.GenerativeModel('gemini-1.5-pro-latest')
15
 
16
  # Chat history
@@ -25,7 +67,7 @@ def extract_text(response_parts):
25
  return response_parts[0].text.strip() if response_parts[0].text else ""
26
 
27
  # Handle "Sor" button click
28
- if st.button('Ask'):
29
  if soru:
30
  response = st.session_state.chat.send_message(soru)
31
  st.session_state.chat.history.append({'role': 'model', 'text': extract_text(response.parts)})
@@ -35,7 +77,7 @@ if st.button('Ask'):
35
  st.experimental_rerun()
36
 
37
  # Display chat history
38
- for message in response.choices[0]['message']['content']:
39
  if message['role'] == 'user':
40
  st.markdown(f'<div style="text-align: right; background-color: #2F2F2F; padding: 10px; border-radius: 10px; margin: 10px; width: fit-content;">👤 Sen: {message["text"]}</div>', unsafe_allow_html=True)
41
  elif message['role'] == 'model':
@@ -46,4 +88,5 @@ if st.button('Yeni Sohbet'):
46
  st.session_state.chat = model.start_chat(history=[])
47
  st.session_state.last_question = ''
48
  st.session_state.last_response = ''
49
- st.experimental_rerun()
 
 
1
+ Hugging Face's logo
2
+ Hugging Face
3
+ Search models, datasets, users...
4
+ Models
5
+ Datasets
6
+ Spaces
7
+ Posts
8
+ Docs
9
+ Solutions
10
+ Pricing
11
+
12
+ Log In
13
+ Sign Up
14
+ Spaces:
15
+
16
+ Erayss
17
+ /
18
+ chat_me
19
+
20
+
21
+ like
22
+ 0
23
+ App
24
+ Files
25
+ Community
26
+ chat_me
27
+ /
28
+ app.py
29
+
30
+ Erayss's picture
31
+ Erayss
32
+ Update app.py
33
+ f3be7f2
34
+ VERIFIED
35
+ 8 days ago
36
+ raw
37
+ history
38
+ blame
39
+ contribute
40
+ delete
41
+ No virus
42
+ 1.94 kB
43
  #!/usr/bin/env python
44
  # coding: utf-8
45
 
 
52
  import os
53
  genai.configure(api_key=os.getenv("key"))
54
 
55
+ st.title('Chat with Me')
56
  model = genai.GenerativeModel('gemini-1.5-pro-latest')
57
 
58
  # Chat history
 
67
  return response_parts[0].text.strip() if response_parts[0].text else ""
68
 
69
  # Handle "Sor" button click
70
+ if st.button('Sor'):
71
  if soru:
72
  response = st.session_state.chat.send_message(soru)
73
  st.session_state.chat.history.append({'role': 'model', 'text': extract_text(response.parts)})
 
77
  st.experimental_rerun()
78
 
79
  # Display chat history
80
+ for message in reversed(st.session_state.chat.history):
81
  if message['role'] == 'user':
82
  st.markdown(f'<div style="text-align: right; background-color: #2F2F2F; padding: 10px; border-radius: 10px; margin: 10px; width: fit-content;">👤 Sen: {message["text"]}</div>', unsafe_allow_html=True)
83
  elif message['role'] == 'model':
 
88
  st.session_state.chat = model.start_chat(history=[])
89
  st.session_state.last_question = ''
90
  st.session_state.last_response = ''
91
+ st.experimental_rerun()
92
+