Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Flask API
|
2 |
from flask import Flask, jsonify
|
3 |
import threading
|
@@ -47,3 +118,5 @@ flask_thread.start()
|
|
47 |
#data = response.json()
|
48 |
|
49 |
#st.write(response) # Zeigt die Daten in der Streamlit-Oberfläche an
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
|
4 |
+
# Streamlit Seite konfigurieren
|
5 |
+
st.set_page_config(
|
6 |
+
page_title="Gemini Chatbot mit Google Search",
|
7 |
+
page_icon="🤖"
|
8 |
+
)
|
9 |
+
|
10 |
+
|
11 |
+
genai.configure(api_key=os.environ["geminiapi"])
|
12 |
+
|
13 |
+
# Modell-Konfiguration
|
14 |
+
generation_config = {
|
15 |
+
"temperature": 0.4,
|
16 |
+
"top_p": 0.95,
|
17 |
+
"top_k": 40,
|
18 |
+
"max_output_tokens": 8192,
|
19 |
+
"response_mime_type": "text/plain",
|
20 |
+
}
|
21 |
+
|
22 |
+
grounding_config = genai.types.GroundingConfig(
|
23 |
+
source_type=genai.types.GroundingSource.GOOGLE_SEARCH
|
24 |
+
)
|
25 |
+
|
26 |
+
model = genai.GenerativeModel(
|
27 |
+
model_name="gemini-2.0-flash-exp",
|
28 |
+
generation_config=generation_config,
|
29 |
+
grounding_config=grounding_config
|
30 |
+
)
|
31 |
+
|
32 |
+
# Chat Session State initialisieren
|
33 |
+
if "chat_session" not in st.session_state:
|
34 |
+
st.session_state.chat_session = model.start_chat(history=[])
|
35 |
+
|
36 |
+
# UI Komponenten
|
37 |
+
st.title("🤖 Gemini Chatbot mit Google Search")
|
38 |
+
user_input = st.text_input("Stelle deine Frage:", key="user_input")
|
39 |
+
|
40 |
+
if user_input:
|
41 |
+
# Prompt mit Sprachaufforderung kombinieren
|
42 |
+
full_prompt = f"{user_input}\nAntworte immer auf Deutsch"
|
43 |
+
|
44 |
+
# Antwort generieren
|
45 |
+
response = st.session_state.chat_session.send_message(full_prompt)
|
46 |
+
|
47 |
+
# Antwort extrahieren
|
48 |
+
if response.candidates:
|
49 |
+
response_text = response.candidates[0].content.parts[0].text
|
50 |
+
else:
|
51 |
+
response_text = "Keine Antwort erhalten"
|
52 |
+
|
53 |
+
# Antwort anzeigen
|
54 |
+
st.subheader("Antwort:")
|
55 |
+
st.write(response_text)
|
56 |
+
|
57 |
+
# Quellen anzeigen falls vorhanden
|
58 |
+
if response.grounding_metadata:
|
59 |
+
st.subheader("Quellen:")
|
60 |
+
for source in response.grounding_metadata.sources:
|
61 |
+
st.markdown(f"- [{source.url}]({source.url})")
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
"""
|
72 |
# Flask API
|
73 |
from flask import Flask, jsonify
|
74 |
import threading
|
|
|
118 |
#data = response.json()
|
119 |
|
120 |
#st.write(response) # Zeigt die Daten in der Streamlit-Oberfläche an
|
121 |
+
|
122 |
+
"""
|