Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,183 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
theme=theme,
|
14 |
-
title="RocketGPT - AI-Powered Chatbot",
|
15 |
-
css="""
|
16 |
-
.gradio-container {background-color: #f0f4f8; padding: 20px;}
|
17 |
-
h1, h2, h3, h4, h5, h6 {color: #4a5568;}
|
18 |
-
.gradio-container .avatar-container {height: 40px; width: 40px; border-radius: 50%; overflow: hidden;}
|
19 |
-
#duplicate-button {margin: auto; color: white; background: #2d3748; border-radius: 100vh; padding: 8px 16px;}
|
20 |
-
.tab-nav-button {background-color: #e2e8f0; border-radius: 8px;}
|
21 |
-
.tab-nav-button.selected {background-color: #cbd5e0;}
|
22 |
-
"""
|
23 |
-
) as demo:
|
24 |
-
gr.Markdown("# 🚀 RocketGPT - AI-Powered Chatbot")
|
25 |
-
|
26 |
-
# Define individual tabs as separate Blocks
|
27 |
-
with gr.Tabs():
|
28 |
-
with gr.Tab("💬 Chat"):
|
29 |
-
gr.HTML("""
|
30 |
-
<iframe src='https://Qwen-QwQ-32B-preview.hf.space'
|
31 |
-
width='100%' height='800px'
|
32 |
-
style='border-radius: 8px; border: none;'></iframe>
|
33 |
-
""")
|
34 |
-
|
35 |
-
with gr.Tab("🗣️ Speech Generator"):
|
36 |
-
gr.HTML("""
|
37 |
-
<iframe src='https://wifix199-Text-to-speech-LuminaIQ.hf.space'
|
38 |
-
width='100%' height='800px'
|
39 |
-
style='border-radius: 8px; border: none;'></iframe>
|
40 |
-
""")
|
41 |
-
|
42 |
-
with gr.Tab("🖼️ Image Generator"):
|
43 |
-
gr.HTML("""
|
44 |
-
<iframe src='https://wifix199-Text-to-image-LuminaIQ.hf.space'
|
45 |
-
width='100%' height='800px'
|
46 |
-
style='border-radius: 8px; border: none;'></iframe>
|
47 |
-
""")
|
48 |
-
|
49 |
-
with gr.Tab("🎥 Video Generator"):
|
50 |
-
gr.HTML("""
|
51 |
-
<iframe src='https://kingnish-instant-video.hf.space'
|
52 |
-
width='100%' height='800px'
|
53 |
-
style='border-radius: 8px; border: none;'></iframe>
|
54 |
-
""")
|
55 |
-
|
56 |
-
with gr.Tab("👨💻 Website Generator"):
|
57 |
-
gr.HTML("""
|
58 |
-
<iframe src='https://Qwen-Qwen2.5-Coder-Artifacts.hf.space'
|
59 |
-
width='100%' height='800px'
|
60 |
-
style='border-radius: 8px; border: none;'></iframe>
|
61 |
-
""")
|
62 |
-
|
63 |
-
# Launch the app with queue support
|
64 |
-
demo.queue(max_size=300)
|
65 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
from langchain.chains import RetrievalQA
|
4 |
+
from langchain.embeddings import OpenAIEmbeddings
|
5 |
+
from langchain.vectorstores import FAISS
|
6 |
+
from langchain.document_loaders import TextLoader
|
7 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
8 |
+
from langchain.llms import OpenAI
|
9 |
+
import os
|
10 |
|
11 |
+
OPENAI_API_KEYS = os.getenv("OPENAI_API_KEYS")
|
12 |
+
|
13 |
+
# Knowledge base for Crustdata APIs
|
14 |
+
docs = """
|
15 |
+
# Crustdata Dataset API
|
16 |
+
|
17 |
+
## Description
|
18 |
+
The Crustdata Dataset API provides access to a wide variety of datasets across different domains. It allows users to search, filter, and retrieve datasets based on categories, tags, and other metadata.
|
19 |
+
|
20 |
+
## Key Endpoints
|
21 |
+
|
22 |
+
### 1. **GET /datasets**
|
23 |
+
- **Description**: Retrieves a list of available datasets.
|
24 |
+
- **Parameters**:
|
25 |
+
- `category` (optional): Filter datasets by a specific category.
|
26 |
+
- `tags` (optional): Filter datasets by tags (comma-separated).
|
27 |
+
- `limit` (optional): Maximum number of datasets to return (default: 10).
|
28 |
+
|
29 |
+
- **Example Request**:
|
30 |
+
```bash
|
31 |
+
curl -X GET "https://api.crustdata.com/datasets?category=finance&tags=economy,stocks&limit=5"
|
32 |
+
```
|
33 |
+
|
34 |
+
- **Example Response**:
|
35 |
+
```json
|
36 |
+
{
|
37 |
+
"datasets": [
|
38 |
+
{
|
39 |
+
"id": "12345",
|
40 |
+
"name": "Global Finance Dataset",
|
41 |
+
"category": "finance",
|
42 |
+
"tags": ["economy", "stocks"]
|
43 |
+
},
|
44 |
+
...
|
45 |
+
]
|
46 |
+
}
|
47 |
+
```
|
48 |
+
|
49 |
+
### 2. **GET /datasets/{id}**
|
50 |
+
- **Description**: Retrieves detailed information about a specific dataset.
|
51 |
+
- **Parameters**:
|
52 |
+
- `id` (required): The unique identifier of the dataset.
|
53 |
+
|
54 |
+
- **Example Request**:
|
55 |
+
```bash
|
56 |
+
curl -X GET "https://api.crustdata.com/datasets/12345"
|
57 |
+
```
|
58 |
+
|
59 |
+
- **Example Response**:
|
60 |
+
```json
|
61 |
+
{
|
62 |
+
"id": "12345",
|
63 |
+
"name": "Global Finance Dataset",
|
64 |
+
"description": "A comprehensive dataset on global financial markets.",
|
65 |
+
"category": "finance",
|
66 |
+
"tags": ["economy", "stocks"],
|
67 |
+
"source": "World Bank"
|
68 |
+
}
|
69 |
+
```
|
70 |
+
|
71 |
+
---
|
72 |
+
|
73 |
+
# Crustdata Discovery and Enrichment API
|
74 |
+
|
75 |
+
## Description
|
76 |
+
The Crustdata Discovery and Enrichment API allows users to enrich their datasets by adding metadata, geolocation information, and other relevant attributes.
|
77 |
+
|
78 |
+
## Key Endpoints
|
79 |
+
|
80 |
+
### 1. **POST /enrich**
|
81 |
+
- **Description**: Enriches input data with additional metadata based on the specified enrichment type.
|
82 |
+
- **Parameters**:
|
83 |
+
- `input_data` (required): A list of data entries to be enriched.
|
84 |
+
- `enrichment_type` (required): The type of enrichment to apply. Supported types:
|
85 |
+
- `geolocation`
|
86 |
+
- `demographics`
|
87 |
+
|
88 |
+
- **Example Request**:
|
89 |
+
```bash
|
90 |
+
curl -X POST "https://api.crustdata.com/enrich" \
|
91 |
+
-H "Content-Type: application/json" \
|
92 |
+
-d '{
|
93 |
+
"input_data": [{"address": "123 Main St, Springfield"}],
|
94 |
+
"enrichment_type": "geolocation"
|
95 |
+
}'
|
96 |
+
```
|
97 |
+
|
98 |
+
- **Example Response**:
|
99 |
+
```json
|
100 |
+
{
|
101 |
+
"enriched_data": [
|
102 |
+
{
|
103 |
+
"address": "123 Main St, Springfield",
|
104 |
+
"latitude": 37.12345,
|
105 |
+
"longitude": -93.12345
|
106 |
+
}
|
107 |
+
]
|
108 |
+
}
|
109 |
+
```
|
110 |
+
|
111 |
+
### 2. **POST /search**
|
112 |
+
- **Description**: Searches for relevant metadata or datasets based on user-provided criteria.
|
113 |
+
- **Parameters**:
|
114 |
+
- `query` (required): The search term or query string.
|
115 |
+
- `filters` (optional): Additional filters to narrow down the search results.
|
116 |
+
|
117 |
+
- **Example Request**:
|
118 |
+
```bash
|
119 |
+
curl -X POST "https://api.crustdata.com/search" \
|
120 |
+
-H "Content-Type: application/json" \
|
121 |
+
-d '{
|
122 |
+
"query": "energy consumption",
|
123 |
+
"filters": {"category": "energy"}
|
124 |
+
}'
|
125 |
+
```
|
126 |
+
|
127 |
+
- **Example Response**:
|
128 |
+
```json
|
129 |
+
{
|
130 |
+
"results": [
|
131 |
+
{
|
132 |
+
"id": "67890",
|
133 |
+
"name": "Energy Consumption Dataset",
|
134 |
+
"category": "energy",
|
135 |
+
"tags": ["consumption", "renewables"]
|
136 |
+
}
|
137 |
+
]
|
138 |
+
}
|
139 |
+
```
|
140 |
+
|
141 |
+
---
|
142 |
+
|
143 |
+
# General Notes
|
144 |
+
- All endpoints require authentication using an API key.
|
145 |
+
- API requests must include the `Authorization` header:
|
146 |
+
```plaintext
|
147 |
+
Authorization: Bearer YOUR_API_KEY
|
148 |
+
```
|
149 |
+
- Response format: JSON
|
150 |
+
- Base URL: `https://api.crustdata.com`
|
151 |
+
"""
|
152 |
+
|
153 |
+
# Split the documentation into chunks for embedding
|
154 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
155 |
+
doc_chunks = text_splitter.create_documents([docs])
|
156 |
+
|
157 |
+
# Embed the documents using OpenAI embeddings
|
158 |
+
embeddings = OpenAIEmbeddings()
|
159 |
+
docsearch = FAISS.from_documents(doc_chunks, embeddings)
|
160 |
+
|
161 |
+
# Create a QA chain
|
162 |
+
qa_chain = RetrievalQA.from_chain_type(
|
163 |
+
llm=OpenAI(model="gpt-3.5-turbo"),
|
164 |
+
retriever=docsearch.as_retriever(),
|
165 |
+
return_source_documents=True
|
166 |
+
)
|
167 |
+
|
168 |
+
# Function to handle user queries
|
169 |
+
def answer_question(question):
|
170 |
+
result = qa_chain.run(question)
|
171 |
+
return result
|
172 |
+
|
173 |
+
# Create a Gradio interface
|
174 |
+
chat_interface = gr.Interface(
|
175 |
+
fn=answer_question,
|
176 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask a question about Crustdata APIs..."),
|
177 |
+
outputs="text",
|
178 |
+
title="Crustdata API Chat",
|
179 |
+
description="Ask any technical questions about Crustdata’s Dataset and Discovery APIs.",
|
180 |
)
|
181 |
|
182 |
+
# Launch the Gradio app
|
183 |
+
chat_interface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|