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