Spaces:
Runtime error
Runtime error
Jyotiyadav
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the pipeline
|
5 |
+
pipe = pipeline(
|
6 |
+
"text-generation",
|
7 |
+
model="DataIntelligenceTeam/mistral_7B_NER",
|
8 |
+
torch_dtype=torch.bfloat16,
|
9 |
+
device_map="auto"
|
10 |
+
)
|
11 |
+
|
12 |
+
# Function to generate output based on input
|
13 |
+
def generate_output(input_text):
|
14 |
+
# Prompt for extracting information
|
15 |
+
prompt = f'''
|
16 |
+
Your task is to extract the information corresponding to the provided labels from the below given email.
|
17 |
+
|
18 |
+
### Labels:
|
19 |
+
* pickup_location: Street address of the origin location of goods.
|
20 |
+
* pickup_cap: Postal code or ZIP code of the pickup location.
|
21 |
+
* pickup_port: Port of pickup, often used in international shipping.
|
22 |
+
* pickup_state: Only Country of pickup location.
|
23 |
+
* delivery_location: Street address of the destination location of goods.
|
24 |
+
* delivery_cap: Postal code or ZIP code of delivery location.
|
25 |
+
* delivery_port: Port of delivery, similar to pickup port.
|
26 |
+
* delivery_state: State or region of delivery location.
|
27 |
+
* total_quantity: Overall quantity of shipped items (e.g., pieces, boxes). Calculate the total_quantity by summing the quantity of all packages.
|
28 |
+
* total_weight: Total weight of the shipment (e.g., kg, lbs). Calculate the total_weight by summing the weights of all packages.
|
29 |
+
* total_volume: Total volume of the shipment (e.g., cubic meters, cubic feet). Calculate the total_volume by summing the volumes of all packages.
|
30 |
+
* quantity: Individual Quantity of a specific item being shipped.
|
31 |
+
* package_type: Individual Type of packaging used (e.g., pallets, cartons).
|
32 |
+
* weight: Individual Weight of a specific package.
|
33 |
+
* measures: Individual Dimensions or measurements of a package.
|
34 |
+
* stackable: Indicates whether the shipment is stackable (True or False).
|
35 |
+
* volume: Individual Volume of a specific package.
|
36 |
+
* commodity: Type of goods or commodities being shipped.
|
37 |
+
* company: Name of the email sending company, also the shipping company or carrier.
|
38 |
+
* incoterms: Choose available options: EXW, FCA, FAS, FOB, CFR, CIF, CPT, CIP, DAP, DPU, DDP.
|
39 |
+
|
40 |
+
For attributes with multiple values, such as measures, volume, weight, package_type, and quantity, provide each value separately in a JSON format.
|
41 |
+
|
42 |
+
### Input data:
|
43 |
+
{input_text}
|
44 |
+
|
45 |
+
### Output:
|
46 |
+
'''
|
47 |
+
|
48 |
+
# Generate the result
|
49 |
+
result = pipe(
|
50 |
+
f"<s>[INST] {prompt} [/INST]",
|
51 |
+
do_sample=True,
|
52 |
+
max_new_tokens=32000,
|
53 |
+
temperature=0.1,
|
54 |
+
top_k=0,
|
55 |
+
top_p=0,
|
56 |
+
num_return_sequences=1,
|
57 |
+
)
|
58 |
+
|
59 |
+
# Return the generated text
|
60 |
+
return result[0]['generated_text']
|
61 |
+
|
62 |
+
# Create a Gradio interface
|
63 |
+
gr.Interface(
|
64 |
+
fn=generate_output,
|
65 |
+
inputs=gr.inputs.Textbox(lines=30, label="Input Email"),
|
66 |
+
outputs=gr.outputs.Textbox(lines=30, label="Extracted Information"),
|
67 |
+
title="Email Information Extraction",
|
68 |
+
description="Extract information from emails based on provided labels.",
|
69 |
+
theme="compact"
|
70 |
+
).launch()
|