Spaces:
Runtime error
Runtime error
File size: 1,286 Bytes
4d08477 583a697 4d08477 583a697 4d08477 583a697 4d08477 ad451a6 4d08477 6f797c1 999f902 4d08477 af1bed7 6f797c1 4d08477 5eb18e7 |
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 |
#Text-generation endpoint for the mistral model
import requests, json
import os
hf_api_key = os.environ.get("HF_TOKEN")
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
headers = {"Authorization": f"Bearer {hf_api_key}",
"Content-Type": "application/json"}
def query(inputs, parameters=None, ENDPOINT_URL=API_URL):
data = {"inputs": inputs}
if parameters is not None:
data.update({"parameters": parameters})
response = requests.request("POST", ENDPOINT_URL, headers=headers, data=json.dumps(data))
return json.loads(response.content.decode("utf-8"))
#Defining text generation function
def generate_text(inputs):
output = query(inputs)
return output[0]['generated_text']
#Gradio Interface
import gradio as gr
gr.close_all()
demo = gr.Interface(fn=generate_text,
inputs=[gr.Textbox(label="Prompt", lines=5, placeholder="Enter your text here...")],
outputs=[gr.Textbox(label="Generated Text", lines=5)],
title="Text Generator",
description="Text generation using `mistralai/Mistral-7B-Instruct-v0.1` model.",
examples=["I like ice cream", "That cat is cute"],
)
demo.launch() |