mehmet0001 commited on
Commit
1757e11
·
verified ·
1 Parent(s): c486a23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -5,6 +5,15 @@ import streamlit as st
5
 
6
  api_key = "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"
7
 
 
 
 
 
 
 
 
 
 
8
  if st.session_state.stage == "crawl-input":
9
  config = st.text_area("Enter the start URL and the limit of crawling (in this format : URL,limit):")
10
  config_btn = st.button("Start crawling!")
@@ -17,35 +26,25 @@ if st.session_state.stage == "crawl-input":
17
  st.session_state.collection = create_database.create_database(txt)
18
  st.write("Crawling is done.")
19
  st.session_state.stage = "prompt-input"
20
-
21
- openai_client = OpenAI(base_url="https://openrouter.ai/api/v1",api_key=api_key)
22
-
23
- prompt_template = """Answer the question only according to the information provided below. Answer only the user's question, dont give additional information.
24
- ## Information :
25
- {}
26
-
27
- ## Question :
28
- # {}"""
29
-
30
- if st.session_state.stage == "prompt-input":
31
  prompt = st.text_area("What would you like to chat about?")
32
- prompt_btn = st.button("Enter")
33
-
34
- if prompt and prompt_btn:
35
- results = st.session_state.collection.query(query_texts=[prompt],n_results=5)
36
- infos = results["documents"][0]
37
-
38
- info_text = ""
39
- for info in infos:
40
- info_text += info + "\n---\n"
41
- info_text = info_text.strip()
42
 
43
- prompt = prompt_template.format(info_text,prompt)
44
-
45
- completion = openai_client.chat.completions.create(
46
- extra_headers={},
47
- extra_body={},
48
- model="deepseek/deepseek-r1:free",
49
- messages=[{"role":"user","content":prompt}])
50
-
51
- st.write((completion.choices[0].message.content)[7:-1])
 
 
 
 
 
 
 
 
 
 
5
 
6
  api_key = "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"
7
 
8
+ openai_client = OpenAI(base_url="https://openrouter.ai/api/v1",api_key=api_key)
9
+
10
+ prompt_template = """Answer the question only according to the information provided below. Answer only the user's question, dont give additional information.
11
+ ## Information :
12
+ {}
13
+
14
+ ## Question :
15
+ # {}"""
16
+
17
  if st.session_state.stage == "crawl-input":
18
  config = st.text_area("Enter the start URL and the limit of crawling (in this format : URL,limit):")
19
  config_btn = st.button("Start crawling!")
 
26
  st.session_state.collection = create_database.create_database(txt)
27
  st.write("Crawling is done.")
28
  st.session_state.stage = "prompt-input"
29
+ else:
 
 
 
 
 
 
 
 
 
 
30
  prompt = st.text_area("What would you like to chat about?")
31
+ prompt_btn = st.button("Enter")
 
 
 
 
 
 
 
 
 
32
 
33
+ if prompt and prompt_btn:
34
+ results = st.session_state.collection.query(query_texts=[prompt],n_results=5)
35
+ infos = results["documents"][0]
36
+
37
+ info_text = ""
38
+ for info in infos:
39
+ info_text += info + "\n---\n"
40
+ info_text = info_text.strip()
41
+
42
+ prompt = prompt_template.format(info_text,prompt)
43
+
44
+ completion = openai_client.chat.completions.create(
45
+ extra_headers={},
46
+ extra_body={},
47
+ model="deepseek/deepseek-r1:free",
48
+ messages=[{"role":"user","content":prompt}])
49
+
50
+ st.write((completion.choices[0].message.content)[7:-1])