Spaces:
Running
Running
update
Browse files- app.py +61 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load environment variables
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
# Initialize Hugging Face client
|
| 10 |
+
client = InferenceClient(
|
| 11 |
+
provider="novita",
|
| 12 |
+
api_key=os.getenv("HF_TOKEN")
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
def chat(message, history):
|
| 16 |
+
"""
|
| 17 |
+
Process chat messages using Hugging Face's Inference Provider
|
| 18 |
+
"""
|
| 19 |
+
try:
|
| 20 |
+
# Format the conversation history
|
| 21 |
+
messages = []
|
| 22 |
+
for human, assistant in history:
|
| 23 |
+
messages.append({"role": "user", "content": human})
|
| 24 |
+
messages.append({"role": "assistant", "content": assistant})
|
| 25 |
+
messages.append({"role": "user", "content": message})
|
| 26 |
+
|
| 27 |
+
# Get response from the model
|
| 28 |
+
completion = client.chat.completions.create(
|
| 29 |
+
model="deepseek-ai/DeepSeek-V3-0324",
|
| 30 |
+
messages=messages,
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
max_tokens=1000
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
return completion.choices[0].message.content
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error: {str(e)}"
|
| 39 |
+
|
| 40 |
+
# Create Gradio interface
|
| 41 |
+
with gr.Blocks(title="DeepSearch - AI Search Assistant") as demo:
|
| 42 |
+
gr.Markdown("# DeepSearch")
|
| 43 |
+
gr.Markdown("Ask anything and get AI-powered responses using state-of-the-art language models.")
|
| 44 |
+
|
| 45 |
+
chatbot = gr.ChatInterface(
|
| 46 |
+
fn=chat,
|
| 47 |
+
examples=[
|
| 48 |
+
"What is the capital of France?",
|
| 49 |
+
"Explain quantum computing in simple terms",
|
| 50 |
+
"Write a short poem about artificial intelligence"
|
| 51 |
+
],
|
| 52 |
+
title="DeepSearch Chat",
|
| 53 |
+
description="Ask me anything!",
|
| 54 |
+
theme=gr.themes.Soft(),
|
| 55 |
+
retry_btn=None,
|
| 56 |
+
undo_btn=None,
|
| 57 |
+
clear_btn="Clear",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
huggingface-hub>=0.20.0
|
| 3 |
+
python-dotenv>=1.0.0
|
| 4 |
+
requests>=2.31.0
|