Spaces:
Runtime error
Runtime error
File size: 1,205 Bytes
5131b33 5b4c169 07fca4f 4ffc5f1 07fca4f 5131b33 d43b4cf 07fca4f 604d57b 4c4e8e3 5131b33 07fca4f 13559a3 203b12e 07fca4f 13559a3 5b4c169 13559a3 07fca4f 5b4c169 07fca4f 5b4c169 07fca4f b96ef93 4c4e8e3 |
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 |
import gradio as gr
import requests
import os
import spaces
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B-Instruct"
api_token = os.environ.get("TOKEN")
headers = {"Authorization": f"Bearer {api_token}"}
@spaces.GPU
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
def generate_response(prompt):
payload = {
"inputs": prompt,
"parameters": {
"max_new_tokens": 2000,
"temperature": 0.7,
"top_p": 0.95,
"do_sample": True
}
}
response = query(payload)
if isinstance(response, list) and len(response) > 0:
return response[0].get('generated_text', '')
elif isinstance(response, dict) and 'generated_text' in response:
return response['generated_text']
return "Désolé, je n'ai pas pu générer de réponse."
def chatbot(message, history):
response = generate_response(message)
return response
iface = gr.ChatInterface(
fn=chatbot,
title="Chatbot Meta-Llama-3-8B-Instruct",
description="Interagissez avec le modèle Meta-Llama-3-8B-Instruct."
)
iface.launch() |