File size: 1,276 Bytes
b2bc43f
 
 
 
 
6b2df0e
b2bc43f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load the model and tokenizer
model_name = "Qwen/Qwen3-0.6B-Base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def process_excel(file, prompt):
    # Read the Excel file
    df = pd.read_excel(file.name)

    # Convert the DataFrame to a string representation
    excel_content = df.to_string(index=False)

    # Combine the prompt with the Excel content
    full_prompt = f"{prompt}\n\nExcel Data:\n{excel_content}"

    # Tokenize the input and generate a response
    inputs = tokenizer(full_prompt, return_tensors="pt")
    outputs = model.generate(**inputs, max_length=500)

    # Decode the output
    result = tokenizer.decode(outputs[0], skip_special_tokens=True)

    return result

# Define the Gradio interface
app = gr.Interface(
    fn=process_excel,
    inputs=[
        gr.File(label="Upload Excel File"),
        gr.Textbox(label="Enter your prompt")
    ],
    outputs=gr.Textbox(label="Result"),
    title="Excel Processing with Qwen3",
    description="Upload an Excel file and enter a prompt to process the data."
)

# Launch the app
app.launch(server_name="0.0.0.0", server_port=7860)