Spaces:
Sleeping
Sleeping
| 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) | |