Nullpointer-KK commited on
Commit
0ec1ce2
·
1 Parent(s): 2e8e1ae

update space

Browse files
Files changed (1) hide show
  1. README.md +145 -16
README.md CHANGED
@@ -1,16 +1,145 @@
1
- ---
2
- title: Test
3
- emoji: 💬
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.42.0
8
- app_file: app.py
9
- pinned: false
10
- hf_oauth: true
11
- hf_oauth_scopes:
12
- - inference-api
13
- short_description: adfed
14
- ---
15
-
16
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CRYPTO RAG CHATBOT - README
2
+ =================================
3
+
4
+ This is a cryptocurrency-focused Retrieval-Augmented Generation (RAG) app.
5
+ It retrieves from your uploaded documents and added URLs, reranks results, and generates
6
+ answers with a chat LLM. It can also route "price" queries to a live price tool for major coins.
7
+
8
+ 1) OPENAI API KEY (REQUIRED; PASTE-ONLY, NEVER SAVED)
9
+ -----------------------------------------------------
10
+ - The chat model requires an OpenAI API key.
11
+ - Paste your key into the "OpenAI API Key" field in the UI.
12
+ - The key is kept in memory for the current session only:
13
+ - It is not written to disk, not bundled in the repository, and not logged.
14
+ - Restarting or refreshing the Space clears it.
15
+ - The key is used only to generate chat responses for this app.
16
+
17
+ 2) QUICK COST ESTIMATE (GPT-4o-mini PRICING)
18
+ --------------------------------------------
19
+ Pricing used: (https://platform.openai.com/docs/pricing)
20
+ - Input: $0.15 per 1,000,000 tokens
21
+ - Output: $0.60 per 1,000,000 tokens
22
+
23
+ Assumptions:
24
+ - 200 input tokens per query
25
+ - 500 output tokens per query
26
+ - 20 queries total
27
+
28
+ Per-query cost:
29
+ - Input: 200 / 1,000,000 * $0.15 = $0.00003
30
+ - Output: 500 / 1,000,000 * $0.60 = $0.00030
31
+ - Total per query = $0.00003 + $0.00030 = $0.00033
32
+
33
+ 20-query session:
34
+ - $0.00033 * 20 = $0.0066
35
+
36
+ Result: Approximately six-tenths of a cent ($0.0066) for the full try, well under the $0.50 budget.
37
+
38
+ 3) FREE OPEN-SOURCE RETRIEVAL MODELS
39
+ ------------------------------------
40
+ - Embeddings: sentence-transformers/all-MiniLM-L6-v2
41
+ - Reranker: cross-encoder/ms-marco-MiniLM-L-6-v2
42
+ These run locally in the Space and are free (no API costs).
43
+
44
+ 4) UPLOADING .PDF / .TXT / .MD FILES (FOR RAG)
45
+ ----------------------------------------------
46
+ - Click "Add files" and select any combination of .pdf, .txt, or .md.
47
+ - The app extracts text (PDFs via pypdf), splits into chunks, and stores them
48
+ with metadata for retrieval.
49
+ - After adding files, click "Build Index" so they are included in search.
50
+
51
+ 5) ADDING MULTIPLE URLS (FOR RAG)
52
+ ---------------------------------
53
+ - Paste one URL per line in the "URLs" box and click "Add URLs".
54
+ - The app fetches and parses the pages (static articles and PDFs work best).
55
+ - After adding URLs, click "Build Index" to include them in retrieval.
56
+
57
+ 6) BUILD INDEX AND RETRIEVAL OPTIONS
58
+ ------------------------------------
59
+ After you add files and/or URLs, click "Build Index". You can tune:
60
+
61
+ - Top-K retrieve (k): how many candidates to pull initially (e.g., 6 to 10).
62
+ - Hybrid alpha (BM25 <-> Dense): blend between keyword BM25 and dense
63
+ similarity. 0.0 = all dense, 1.0 = all BM25. A balanced default is 0.5.
64
+ - Rerank Top-K: how many of the retrieved candidates the cross-encoder reranks
65
+ (e.g., 3 to 8). The final answer uses the top reranked passages.
66
+
67
+ If results seem off:
68
+ - Increase Top-K for better recall.
69
+ - Adjust alpha (higher favors keywords; lower favors semantic similarity).
70
+ - Increase Rerank Top-K for stronger final ordering (slightly more CPU).
71
+
72
+ 7) STREAMING RESPONSES (SELECTABLE)
73
+ ---------------------------------
74
+ - Streaming ON: words appear live as the model generates.
75
+ - Streaming OFF: you receive a single final answer after generation finishes.
76
+ Toggle this with the "Streaming" checkbox.
77
+
78
+ 8) CHAT MODEL CHOICE (FIXED FOR NOW)
79
+ ------------------------------------
80
+ - The chat model is fixed in this version of the app for reliability and cost
81
+ control. If you need a different model, it can be changed in code and
82
+ redeployed; the UI currently does not expose a model selector.
83
+
84
+ 9) LIVE PRICE SEARCH FOR MAJOR COINS + ROUTING
85
+ ----------------------------------------------
86
+ - If your question looks like a price query (for example: "BTC price",
87
+ "price of ETH", "SOL price in USD"), the app routes to a tool instead of RAG:
88
+ - It calls a public price API (for example, CoinGecko) to get the latest
89
+ price for major coins such as BTC, ETH, SOL, and XRP.
90
+ - It can also show the Fear and Greed Index for market sentiment.
91
+ - Routing logic: the pipeline checks your query for price-intent keywords
92
+ ("price", "quote", "market cap", "ATH", and similar). If matched, it uses
93
+ the tools route; otherwise it uses the RAG route (retrieve -> rerank -> answer).
94
+
95
+ 10) QUICK START
96
+ ---------------
97
+ 1. Initialize pipeline (if manual init is enabled).
98
+ 2. Paste your OpenAI API key (not saved).
99
+ 3. Add files and/or add URLs.
100
+ 4. Click Build Index.
101
+ 5. Ask questions. E.g. "what is Ethereum vs Solana?", "What is bitcoin strength and weakness?"
102
+ 6. For prices, try queries like "ETH price", "SOL quote", "XRP price in USD".
103
+
104
+ NOTES
105
+ -----
106
+ - This tool is for research and education only. It is not financial advice.
107
+ - For best results, use focused, well-structured documents and reputable URLs.
108
+
109
+
110
+
111
+ ### Installation and Execution (for Gradio UI)
112
+ ---------------
113
+ 1. **Create a new Python environment:**
114
+
115
+ ```bash
116
+ python -m venv .venv
117
+ ```
118
+
119
+ 2. **Activate the environment:**
120
+
121
+ For macOS and Linux:
122
+
123
+ ```bash
124
+ source .venv/bin/activate
125
+ ```
126
+
127
+ For Windows:
128
+
129
+ ```bash
130
+ .venv\Scripts\activate
131
+ ```
132
+
133
+ 3. **Install the dependencies:**
134
+
135
+ ```bash
136
+ pip install -r requirements.txt
137
+ ```
138
+
139
+ 4. **Run the application:**
140
+
141
+ ```bash
142
+ python app.py
143
+ ```
144
+
145
+