Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Hugging Face API details
|
5 |
+
HF_API_TOKEN = "your_huggingface_api_token" # Replace with your API key
|
6 |
+
MODEL_NAME = "mistralai/Mistral-7B-Instruct" # Choose an LLM model
|
7 |
+
|
8 |
+
|
9 |
+
# Function to query the LLM
|
10 |
+
def extract_info(sentence):
|
11 |
+
prompt = f"""
|
12 |
+
Extract the following information from the given sentence:
|
13 |
+
- Action (normalized to "add" or "remove")
|
14 |
+
- Item name(s)
|
15 |
+
- Quantity (exact number, "some", "all", or null if unspecified)
|
16 |
+
- Location (null if not mentioned)
|
17 |
+
Sentence: "{sentence}"
|
18 |
+
Provide the response in structured JSON format.
|
19 |
+
"""
|
20 |
+
|
21 |
+
response = requests.post(
|
22 |
+
f"https://api-inference.huggingface.co/models/{MODEL_NAME}",
|
23 |
+
headers={"Authorization": f"Bearer {HF_API_TOKEN}"},
|
24 |
+
json={"inputs": prompt}
|
25 |
+
)
|
26 |
+
return response.json()
|
27 |
+
|
28 |
+
# Gradio UI
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=extract_info,
|
31 |
+
inputs=gr.Textbox(label="Enter a sentence"),
|
32 |
+
outputs=gr.JSON(label="Extracted Information"),
|
33 |
+
title="Action & Item Extractor",
|
34 |
+
description="Enter a sentence, and the model will extract the action, item name, quantity, and location."
|
35 |
+
)
|
36 |
+
|
37 |
+
iface.launch()
|