Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import requests
|
|
|
4 |
|
5 |
# Load the Hugging Face token from environment variables (secrets)
|
6 |
token = os.environ.get("Key2") # Replace "KEY2" with your secret key name
|
@@ -25,20 +26,78 @@ def query_huggingface_api(prompt, max_new_tokens=50, temperature=0.7, top_k=50):
|
|
25 |
st.error(f"Error: {response.status_code} - {response.text}")
|
26 |
return None
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# Streamlit App
|
29 |
def main():
|
30 |
-
st.title("
|
31 |
st.write("Enter a prompt and get a response from the model.")
|
32 |
|
33 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
prompt = st.text_input("Enter your prompt:")
|
35 |
if prompt:
|
36 |
st.write("**Prompt:**", prompt)
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Query the Hugging Face API
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import requests
|
4 |
+
from langdetect import detect
|
5 |
|
6 |
# Load the Hugging Face token from environment variables (secrets)
|
7 |
token = os.environ.get("Key2") # Replace "KEY2" with your secret key name
|
|
|
26 |
st.error(f"Error: {response.status_code} - {response.text}")
|
27 |
return None
|
28 |
|
29 |
+
# Function to detect language
|
30 |
+
def detect_language(text):
|
31 |
+
try:
|
32 |
+
return detect(text)
|
33 |
+
except:
|
34 |
+
return "en" # Default to English if detection fails
|
35 |
+
|
36 |
# Streamlit App
|
37 |
def main():
|
38 |
+
st.title("RAG Model with Advanced Query Translation and Indexing")
|
39 |
st.write("Enter a prompt and get a response from the model.")
|
40 |
|
41 |
+
# Sidebar for options
|
42 |
+
st.sidebar.title("Options")
|
43 |
+
|
44 |
+
# Query Translation Options
|
45 |
+
st.sidebar.header("Query Translation")
|
46 |
+
query_translation = st.sidebar.selectbox(
|
47 |
+
"Select Query Translation Method",
|
48 |
+
["Multi-Query", "RAG Fusion", "Decomposition", "Step Back", "HyDE"]
|
49 |
+
)
|
50 |
+
|
51 |
+
# Indexing Options
|
52 |
+
st.sidebar.header("Indexing")
|
53 |
+
indexing_method = st.sidebar.selectbox(
|
54 |
+
"Select Indexing Method",
|
55 |
+
["Multi-Representation", "Raptors", "ColBERT"]
|
56 |
+
)
|
57 |
+
|
58 |
+
# LLM Parameters
|
59 |
+
st.sidebar.header("LLM Parameters")
|
60 |
+
max_new_tokens = st.sidebar.slider("Max New Tokens", 10, 100, 50)
|
61 |
+
temperature = st.sidebar.slider("Temperature", 0.1, 1.0, 0.7)
|
62 |
+
top_k = st.sidebar.slider("Top K", 1, 100, 50)
|
63 |
+
|
64 |
+
# System Prompt
|
65 |
+
st.sidebar.header("System Prompt")
|
66 |
+
default_system_prompt = "You are a helpful assistant."
|
67 |
+
system_prompt = st.sidebar.text_area("System Prompt", default_system_prompt)
|
68 |
+
|
69 |
+
# Main Content
|
70 |
+
st.header("Input Prompt")
|
71 |
prompt = st.text_input("Enter your prompt:")
|
72 |
if prompt:
|
73 |
st.write("**Prompt:**", prompt)
|
74 |
|
75 |
+
# Detect Language
|
76 |
+
language = detect_language(prompt)
|
77 |
+
st.write(f"**Detected Language:** {language}")
|
78 |
+
|
79 |
+
# Query Translation
|
80 |
+
if st.button("Apply Query Translation"):
|
81 |
+
st.write(f"**Applied Query Translation Method:** {query_translation}")
|
82 |
+
# Implement query translation logic here
|
83 |
+
# Example: Generate multiple queries for Multi-Query
|
84 |
+
if query_translation == "Multi-Query":
|
85 |
+
queries = [f"{prompt} - Query {i}" for i in range(3)]
|
86 |
+
st.write("**Generated Queries:**", queries)
|
87 |
+
|
88 |
+
# Indexing
|
89 |
+
if st.button("Apply Indexing"):
|
90 |
+
st.write(f"**Applied Indexing Method:** {indexing_method}")
|
91 |
+
# Implement indexing logic here
|
92 |
+
# Example: Indexing with ColBERT
|
93 |
+
if indexing_method == "ColBERT":
|
94 |
+
st.write("Indexing with ColBERT...")
|
95 |
+
|
96 |
# Query the Hugging Face API
|
97 |
+
if st.button("Generate Response"):
|
98 |
+
response = query_huggingface_api(prompt, max_new_tokens, temperature, top_k)
|
99 |
+
if response:
|
100 |
+
st.write("**Response:**", response)
|
101 |
|
102 |
if __name__ == "__main__":
|
103 |
main()
|