Abobasnik commited on
Commit
06d2c4c
·
verified ·
1 Parent(s): 062d855

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +51 -39
src/streamlit_app.py CHANGED
@@ -1,40 +1,52 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import google.generativeai as genai
3
+ from openai import OpenAI
4
+ import os
5
+
6
+ # Подключаем ключи из секретов HF
7
+ OPENAI_KEY = os.environ.get("OPENAI_API_KEY")
8
+ GEMINI_KEY = os.environ.get("GEMINI_API_KEY")
9
+
10
+ # Настройка моделей
11
+ client = OpenAI(api_key=OPENAI_KEY)
12
+ genai.configure(api_key=GEMINI_KEY)
13
+ gemini_model = genai.GenerativeModel('gemini-1.5-pro') # Pro версия мощнее!
14
+
15
+ st.title("🌌 Синтез Разума: Gemini 3 Pro + GPT-4o")
16
+
17
+ query = st.text_input("Введите ваш запрос:", placeholder="Напиши код или реши задачу...")
18
+
19
+ if st.button("Запустить Гибрид"):
20
+ with st.spinner("Происходит слияние интеллектов..."):
21
+ try:
22
+ # ШАГ 1: GPT создает фундамент и логику
23
+ gpt_res = client.chat.completions.create(
24
+ model="gpt-4o-mini",
25
+ messages=[{"role": "user", "content": query}]
26
+ )
27
+ base_content = gpt_res.choices[0].message.content
28
+
29
+ # ШАГ 2: Gemini анализирует ответ GPT, расширяет его и добавляет детали
30
+ prompt = f"""
31
+ Изначальный запрос: {query}
32
+ Базовый ответ от GPT: {base_content}
33
+
34
+ Твоя задача — выступить в роли супер-интеллекта.
35
+ Возьми за основу ответ GPT, исправь в нем любые неточности, добавь глубокие детали,
36
+ которые знает только Gemini, и выдай финальный, идеальный вариант.
37
+ """
38
+
39
+ final_res = gemini_model.generate_content(prompt)
40
+
41
+ # ВЫВОД РЕЗУЛЬТАТА
42
+ st.markdown("### 🤖 Итоговый ответ Гибрида:")
43
+ st.write(final_res.text)
44
+
45
+ with st.expander("Посмотреть, как они работали (Логи)"):
46
+ st.subheader("Черновик от GPT:")
47
+ st.write(base_content)
48
+
49
+ except Exception as e:
50
+ st.error(f"Ошибка в системе: {e}")
51
+
52
+ # Добавляем файл requirements.txt, чтобы всё заработало